Hi,

I'm having trouble deciding what the best plan is for the arrangement of the components of a new project that I'm starting.

The project is going to be written as a series of mod_perl handlers - one for the main "home page", and others for various sub-components. Each handler is implemented by a separate module (all sub-classes of a common base class). I don't want to have to configure a separate Location for each sub-component.

It also needs to have access to various static resources (images, stylesheets, JavaScript libraries etc.).

Thus, I want to have something like this:

/myproject                 [mp1]
/myproject/component1   [mp1]
/myproject/component2   [mp1]
...
/myproject/images       [static]
/myproject/javascript   [static]
/myproject/stylesheets  [static]

The question is: What is the best way to configure this?

So far I've come up with two options:

OPTION 1. Specify a /myproject Location with "dispatcher" method as the mod_perl handler; then specify a LocationMatch for the images, javascript and stylesheets that overrides the /myproject Location:

<Location /myproject>
   SetHandler perl-script
   PerlHandler MyProject->dispatcher
</Location>

<LocationMatch "^/myproject/(images|javascript|stylesheets)">
   SetHandler default-handler
</LocationMatch>

The "dispatcher" method there looks at the URI requested and either returns DECLINED (or 404?) if it doesn't recognise it, or else loads the appropriate MyProject sub-class and then runs the real content generation routine in that (i.e. a routine like I would have specified as the handler for that URI if I had configured a separate Location for each component).

This seems to have a minor problem in practice -- if I request a directory, rather than a file, in one of the "static" locations (e.g. "/myproject/images" or "/myproject/images/") then the dispatcher method gets called! The LocationMatch override only seems to work if I request a file (e.g. "/myproject/images/piccy1.jpg"). Thus, I need to put some extra code into the dispatcher to repeat the pattern match for the "static" locations, and change the handler to the default-handler and return DECLINED if it has received such a URI.

OPTION 2. Specify a /myproject Location with a PerlFixupHandler that behaves very much like the dispatcher above, except that it actually sets the handler to PerlHandler and assigns the appropriate callback method (i.e. the content generation routine in the component sub-class) when it spots a recognised component URI; otherwise it just returns DECLINED, leaving the request to be handled by the default-handler:

<Location /myproject>
   PerlFixupHandler MyProject->fixup
</Location>

(Am I correct in thinking that I don't need to specify "SetHandler: perl-script" for a PerlFixupHandler? That's only for the main PerlHandler response handler, isn't it?)

Does either of these options have any benefit over the other? Are there other better ways to do it?

Thanks in advance,
- Steve



Reply via email to