|
(You are
Anonymous)
|
mod_perl handlers for CGI::ApplicationAlthough most examples in the CGI::Application documention show instance scripts as cgi scripts, it is possible to create an instance script that can be a mod_perl handler as well. To setup a mod_perl-compatible instance script, you need to take the following steps, Option A - Self-contained solutionUsing this option you can skip creating a separate mod_perl instance script. Add the following to your httpd.conf configuration (or .htaccess if permissions allow): PerlHandler "sub { use My::Module; My::Module->new(PARAMS [=> {p1 =]> 1, p2 => 2})->run(); return 200; }"
This should be placed inside a Location or Directory container which is setup to be handled by Perl. For example: <Location /my/module>
SetHandler perl-script
PerlSendHeader On
PerlHandler "sub { use My::Module; My::Module->new(PARAMS [=> {p1 =]> 1, p2 => 2})->run(); return 200; }"
</Location>
Note: See this discussion on the mailing list if you are using mp2. Option B - Jesse's solution1. Add the following to your Application module: package My::CGIApp::Module;
use base qw/CGI::Application/;
use Apache::Constants ':response';
sub handler ($$) {
my ($pkg, $r) = @_;
# Instantiate and run() your CGI::Application module
my $self = $pkg->new();
$self->run();
return OK;
}
This code is a replacement for the instance script. 2. Configure mod_perl to use your module by adding the following to the ".htaccess" file in the directory in which you want your application to run: <Perl>
use My::CGIApp::Module;
</Perl>
PerlHandler My::CGIApp::Module->handler
See also: * [http://www.mail-archive.com/cgiapp@lists.erlbaum.net/msg00104.html related mailing list discussion] |