Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

upgrading Apache::AuthCookieDBI application to mod_perl2

by geektron (Curate)
on Aug 21, 2006 at 16:26 UTC ( #568598=perlquestion: print w/ replies, xml ) Need Help??
geektron has asked for the wisdom of the Perl Monks concerning the following question:

One of our application servers has recently been upgraded to Apache2/mod_perl2 ( Apache v2./ mod_perl 2.0.20 ), and what appeared to be a simple job of converting an Apache::AuthCookieDBI login.cgi to use the new APIs has turned into a ball of confusing wax.

Apache::AuthCookieDBI's login.cgi (or .pl ) looks like this in 1.x:

#!/usr/bin/perl use strict; use HTML::Template; use Apache; + use constant TMPL_PATH => '/home/httpd/domain.com/html/app_templates'; use constant TMPL_FILE => 'login.tmpl'; my $r = Apache->request; $r->status(200); my $destination; my $authcookiereason; if ( $r->prev() ) { # we are called as a subrequest. $destination = $r->prev()->args() ? $r->prev()->uri() . '?' . $r->prev->args() : $r->prev()->uri(); $authcookiereason = $r->prev()->subprocess_env( 'AuthCookieRea +son' ); } else { $destination = $r->args( 'destination' ); $authcookiereason = $r->args( 'AuthCookieReason' ); } $r->log_error( "previous was: $destination" ); my $reason = $r->prev->subprocess_env("AuthCookieReason"); my $tmpl = HTML::Template->new( path => TMPL_PATH, filename => TMPL_FILE ); my $msg = ( $authcookiereason and $authcookiereason ne 'no_cookie' ? 1 + : 0 ); $tmpl->param( REASON => $msg ); $tmpl->param( uri => $destination ); my $form = $tmpl->output(); $r->no_cache(1); my $x = length($form); $r->content_type("text/html"); $r->header_out("Content-length","$x"); $r->header_out("Pragma", "no-cache"); $r->send_http_header; $r->print($form);

After I read the renaming documentation and applied the changes, the code should look something like this:

#!/usr/bin/perl use strict; use HTML::Template; use Apache2::RequestUtil (); use constant TMPL_PATH => '/home/httpd/domain.com/templates'; use constant TMPL_FILE => 'login.tmpl'; my $r = Apache2::RequestUtil->request(); $r->status(200); .....
Yet, when the handler is fired off, the following error ends up in the error_log:
[Mon Aug 21 09:44:27 2006] [error] [client xx.xx.xx.xx] Can't locate o +bject method "request" via package "Apache2::RequestUtil" at /home/ht +tpd/domain.com/html/login.cgi line 12.

I thought a simple renaming of  my $r = Apache->request(); to  my $r = Apache2::RequestUtils->request() would suffice ... but that doesn't seem to be the case. Is there another renaming gotcha (i.e. some prereq) that I'm missing?

Comment on upgrading Apache::AuthCookieDBI application to mod_perl2
Select or Download Code
Re: upgrading Apache::AuthCookieDBI application to mod_perl2
by Khen1950fx (Canon) on Aug 22, 2006 at 06:03 UTC
    Based on my experience, there are 4 gotchas that need to be looked at. First, go through the httpd.conf and replace PerlModule Apache::SomeCoreModule with PerlModule Apache2::SomeCoreModule. This needs to be done for every directive. Second, the same thing has to be done with the mod_perl : Change  mod_perl to  mod_perl2. Third, has CGI been upgraded? Fourth, the one that I always seem to forget---you'll have to set the environmental variable for mod_perl:

    $ENV{MOD_PERL_API_VERSION} to the version that you are using

      Only the fourth gotcha is one about which I'm not sure. I'll look at it, and see how much further I can get. Thanks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-07-13 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (251 votes), past polls