| Previous | Next
mod_perl HandlersTo understand mod_perl, you should understand how the Apache server works. When Apache receives a request, it processes it in several stages. First, it translates the URL to the associated resource (i.e., filename, CGI script, etc.) on the server machine. Then it checks to see if the user is authorized to access that resource, perhaps by requesting and checking an ID and password or hostname and IP address. Once the user has passed inspection, the server figures out the kind of data it's sending back (e.g., it decides a file ending in html is probably a At each stage of this process, Apache looks for routines to "handle" the request. That is, if Apache doesn't find handlers you've told it to use, it knows to use its own. For example, if you've enabled CGI programs in httpd.conf, Apache knows to execute programs that live in cgi-bin if it encounters the <Location /cgi-bin> ... SetHandler cgi-script ... </Location> mod_perl allows you to write your own handlers in Perl by embedding the Perl runtime library directly into the Apache httpd server executable. To use mod_perl for CGI (which is all that most people want to do with it), assign the SetHandler perl-script PerlHandler Apache::Registry
To use other handlers, you don't need to reassign <Location /snoop/> PerlLogHandler Apache::DumpHeaders </Location> For this to work, mod_perl must have been built with the logging hooks enabled (as described in the previous section), and the Apache::DumpHeaders module must have been installed. mod_perl looks in Apache::DumpHeaders for a routine called The following is a list of each of the handler directives that can be enabled by mod_perl and the stages that each is used for. Only
You can write your own handlers for each of these stages. But there are also dozens of modules that you can download from CPAN, some of which are listed at the end of this chapter. |