http://www.perlmonks.org?node_id=568598

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?

Replies are listed 'Best First'.
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.