[cgiapp] CGI::Application & mod_perl 2

Michael Peters mpeters at plusthree.com
Sun Nov 11 17:10:18 EST 2007


Jon Daily wrote:

> I am porting a CGI::Application from CGI to mod_perl 2.
> 
> My first question is if there is a recommended resource for using
> CGI::Application and mod_perl 2 together that I should use?
> 
> I did come across Michael Peters' CGI::Application::Plugin::Apache
> module on CPAN.  I am attempting to use this to ease the transition,
> however I am running into some issues when dealing with the session.

There really shouldn't be a hard transition between C::A and mod_perl. C::A
encourages you to write your code in a way that is friendly to mod_perl
(encapsulated in methods). If you're just planning on using Apache::Registry for
your application then you shouldn't need to do anything else.

It's only if you need to take advantage of some of the more advanced features of
mod_perl (filters, bucket brigades, etc) do you need to worry about converting
your application into a mod_perl Handler.

I like C::A::P::Apache if I want to use Apache::Request instead of CGI.pm. But
remember, if other things expect $self->query to be a CGI.pm object (like
C::A::P::Session probably does) then you will have problems.

> And when I try to access $self->session I get the following server error,
> 
> [error] Error executing class callback in init stage: Can't locate
> auto/Apache2/Request/cookie.al in @INC 

This is because Apache2::Request does not have a cookie() method. I'd recommend
dropping C::A::P::Apache if you want to guarantee that it plays well with all
other plugins. If you however do want to stick with C::A::P::Apache, then try
putting this in your config:

  PerlSetVar CAPA_CGI_Compat On

It will use CGI::Application::Plugin::Apache::Request as $self->query instead of
Apache::Request. C::A::P::Apache::Request is a little more like CGI.pm than
Apache::Request is.

-- 
Michael Peters
Developer
Plus Three, LP



More information about the cgiapp mailing list