On Thu, 2002-03-21 at 03:30, Andy Huhn wrote: > Hello all, > > I'm trying to set up my CGI::Application descendent with mod_perl. > I'm a newbie, so please bear with me. I found a note in the mail > archive from Jesse where he suggests the following (quote from his > message): > > -------------------------- > > > Speaking of mod_perl, I was wondering if there is a generic > > PerlHandler for bootstrapping a CGI::Application. > > Not quite generic, but pretty simple: > > 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; > } > > sub setup { > # Etc.... > } > > > If you choose to do this, start thinking of your handler() as your > "instance > script". I've done this in cases where I truly want the CGI-App to > handle > all requests in a particular directory hierarchy. > > ---------------------------- > > I'm a bit confused by the above...should the above snippet be part of > httpd.conf? Should be part of a script that is in httpd.conf as a > PerlRequire line? It looks like it is part of the CGI::Application > descendent, I've gathered that much...but I'm not sure how to connect > it to Apache/mod_perl.
If you are just starting with mod_perl, then I would suggest not jumping straight into writing Handlers (like the above script is doing). There are several ways that you can get mod_perl to execute your CGI::Application modules: 1. The easiest would be using the Apache::Registry module to run your current instance script, which should require no changes at all. just add the following to your httpd.conf: Alias /perl/ /usr/local/apache/perl/ <Location /perl> SetHandler perl-script PerlHandler Apache::Registry PerlSendHeader On Options +ExecCGI </Location> (verbatim from pg 42 of Writing Apache Modules with Perl and C by Lincoln Stein & Doug MacEachern, a must have for anyone serious about mod_perl) Now you can add your regular CGI based instance script to /usr/local/apache/perl/ and your code will be running under mod_perl. Do a perldoc on Apache::Registry for more info, and read http://perl.apache.org/guide/ for lots of useful hints on mod_perl. 2. You can write a custom handler like Jesse has provided above. This is slightly more difficult, but also slightly more efficient then the Apache::Registry method (for most people the difference would be negligable) To use Jesse's Perl Handler code, you would have to add a couple of lines to your httpd.conf file, and add his "handler" subroutine into your module. PerlModule My::CGIApp::Module <Location /cgiapp> SetHandler perl-script PerlHandler My::CGIApp::Module </Location> Now whenever a user calls the URL http://myserver.com/cgiapp Apache will call the 'handler' subroutine in the module My::CGIApp::Module, and all output of that function will be sent to the browser. 3. You could use an anonymous handler in your httpd.conf that calls your module. This has the benefit of not requiring any code changes to your Module, however, this looks more complex to anyone browsing the httpd.conf file and may not be appropriate in your situation. PerlModule My::CGIApp::Module <Location /cgiapp> SetHandler perl-script PerlHandler "sub { My::CGIApp::Module->new()->run(); return OK; }" </Location> This last one should not require any changes to your CGIApp modules. Here we are supplying mod_perl with an anonymous subroutine, which will be executed when the http://myserver.com/cgiapp URL is called. It just creates a new instance of the module and calls the run method right after. If anyone who has been using perl scripts with Apache and hasn't looked at mod_perl, I really recommend you check it out. It is a fantastic product and has one of the best support groups I have ever come across (the mod_perl mailing list). There is ample documentation to get users of all levels started (http://perl.apache.org/guide/), and you'll be amazed at how your scripts will fly... Cees --------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/cgiapp@lists.vm.com/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]