View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Tyler MacDonald > ModPerl-PackageRegistry-0.02 > ModPerl::PackageRegistry



Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  


ModPerl::PackageRegistry - Map URIs to perl package namespaces



 <Location /dynamic>
  SetHandler perl-script
  PerlResponseHandler ModPerl::PackageRegistry
  PackageNamespace MyWebsite::pages
  PackageBase /dynamic
  PackageIndex index
  PackageHandler ->page


 package MyWebsite::pages::index;

 use strict;
 use warnings;
 use Apache2::RequestRec ();
 use Apache2::Const q(OK);
 return 1;
 sub page {
     my($class, $r) = @_;
     return OK;


This mod_perl2 handler allows you to directly map a path in your apache 2.x server to a package namespace in perl. When the handler is invoked, it transforms the URI requested into the name of a perl module, and if that module is found, executes the handler specified by the PackageHandler directive.


The transformation is done as follows:

We then attempt to load the module. If loading the module is successful, then we try to invoke it's handler. The handler is specified by the PackageHandler directive. (By default, it is set to the mod_perl default, handler). If you would like your handler to be invoked as a method rather than a function, then place a "->" in front of the method's name, like so:

 PackageHandler ->method

At that point, ModPerl::PackageRegistry is done it's work and the rest is up to you!


The Directory Must Exist

Apache needs to be able to at least find a directory to serve from, even if the content it's serving is from a perl namespace. One way around this is to make your DocumentRoot the start of your perl namespace, eg:

 DocumentRoot /usr/local/lib/perl/5.8.4/MyWebsite/pages


PackageIndex will only work correctly if ModPerl::PackageRegistry is the handler for your entire directory tree. This is because of the way Apache interprets the DirectoryIndex directive.

If you have a handler for ".pl" files, that handler will be invoked when you request /, whether or not actually exists.

However, if you request /, and that is resolved to / by a DirectoryIndex directive, must exist or else apache2 will return a NOT_FOUND response without ever invoking your handler.

If you wish to mix static and dynamic content in the same directory tree, there are three ways (that I know of) to get around this problem.


Tyler "Crackerjack" MacDonald <>.

The "TestCommon::LogDiff" package, used by the test suite, was pilfered from the mod_perl 2.0.2 distribution.


This is free software; you may redistribute it under the same terms as perl itself.

syntax highlighting: