Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Problem running CGI::Application under modperl2

by scorpio17 (Canon)
on Mar 26, 2007 at 21:18 UTC ( [id://606666]=perlquestion: print w/replies, xml ) Need Help??

scorpio17 has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I have a CGI::Application based webapp that runs fine as a normal cgi-bin script, but I'm trying to evolve it into a mod_perl handler for performance reasons.

I'm using the following environment:
Apache 2.0.59 (Unix)
mod_perl 2.0.3
perl 5.8.5
Red Hat Enterprise Linux version 4
All perl modules listed below refer to the latest versions currently on CPAN.
You can assume that I restart the web server after any edits.

What follows is the smallest example I can write to reproduce the problem:

package MyApp::Small; use base 'CGI::Application'; #use CGI::Application::Plugin::Apache qw(:all); # Note#3 use strict; use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::RequestUtil (); #use CGI::Application::Plugin::Session; # Note#1 #use CGI::Application::Plugin::Authentication; # Note#2 use Apache2::Const -compile => qw(OK); sub handler : method { my ($pkg, $r) = @_; my $self = $pkg->new(); $self->run(); return Apache2::Const::OK; } sub setup { my $self = shift; $self->start_mode('mode1'); $self->run_modes( 'mode1' => 'mode1', 'mode2' => 'mode2', ); } sub mode1 { my $self = shift; my $output = "<p>This is page 1.\n"; return $output; } sub mode2 { my $self = shift; my $output = "<p>This is page 2.\n"; return $output; } 1;
In my apache config file, I have the following:
<Location /small> SetHandler perl-script PerlResponseHandler MyApp::Small </Location>

So, as shown above, I can access the URL http://myhost.com/small and I see the message "This is page 1."

If I uncomment the line indicated by Note#1, everything still works.

However, if I uncomment the line indicated by Note#2, I get the following error in the apache log file:

Error executing class callback in prerun stage:
Failed to Create CGI::Session object ::
Reason: new(): failed:
query object CGI=HASH(0x841395c) does not support cookie() and param() methods:
Can't locate Apache/RequestUtil.pm in @INC

At this point, I thought the problem was with using CGI.pm behind the scenes in CGI::Session (which is used by the Authentication plugin) so I tried using the CGI::Application::Plugin::Apache module, which is supposed to allow easy migration to mod_perl. But after uncommenting the line in Note#3, I get this error:

Usage: Apache2::RequestUtil::request(classname, svr=Nullsv)
at /path/to/libs/CGI/Application/Plugin/Apache.pm line 64.

This error remains even if I go back and comment out the lines indicated by Note#1 and Note#2.

I've searched online (including the archives here) and so far have been unable to figure out where I'm going wrong.

Any help will be greatly appreciated!

Thanks!

UPDATE: As it turns out, I did not have the latest version of every module from CPAN. I had installed the latest CGI.pm under my home directory, but an older version installed previously was ahead of it in @INC, so I wasn't using the version that I thought I was. Now that I've corrected that, problems #1 and #2 have gone away.

And #3 is a known problem (thanks mpeters!).

Replies are listed 'Best First'.
Re: Problem running CGI::Application under modperl2
by mpeters (Chaplain) on Mar 26, 2007 at 21:51 UTC
    As far as #2 goes, I'm not sure why that's happening. It should work. CGI.pm should be good enough. Now, for #3 that's a known issue with CGI::Application::Plugin::Apache on mod_perl 2. I've had the fix in my code for a while but just haven't uploaded it to CPAN. I have repented and it's now in the PAUSE queue, so it should be available soon.

    -- More people are killed every year by pigs than by sharks, which shows you how good we are at evaluating risk. -- Bruce Schneier

      Thanks for the info.

      I experienced apache complaining about 'Apache::RequestUtil' not being found after doing an up2date on RedHat Enterprise Linux 4 system.

      The custom mod_perl applications that were trying to start depend on CGI.pm so per your experience I installed the latest version of CGI.pm (3.33) via cpan and that resolved the startup error. <sigh of relief>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://606666]
Approved by philcrow
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-24 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found