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?


In reply to upgrading Apache::AuthCookieDBI application to mod_perl2 by geektron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.