Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Fellow monks,

I'm trying to create a subclass of Apache::Request for an application here at work, and I just can't seem to get my head around why it's not working.

The current application passes data to various functions via Apache::Session::Postgres and there is no consistency between the (many) developers who've worked on the system; in one function, everything may be localized into a session "namespace", while another may dump the variables directly into the root of the session hash, or they may combine the two. I'd like to fix this. The data still needs to be stored in some sort of session, as most of the application is multiple, "wizard" type forms.

I figured it would be nice to subclass the Apache::Request object and place various methods for storing the values in the inherited request object. I can't seem to get this working and I've hit a wall. I've got this so far:

# Apache::Request subclass use strict; use Log::Log4perl; package My::Apache::Request; use Apache::Request; sub new { my ( $class, @args ) = @_; return bless { r=>Apache::Request->new(@args) }, $class; } sub LOGGER { my $self = shift; my $log = shift || 'WebApp'; return Log::Log4perl->get_logger( $log ); } 1;

Then, I have a handler module called from a PerlHandler My::Apache::Handler line in the httpd.conf file. That handler doesn't do much, as I've distilled it down to nothing during debugging:

# Handler use strict; package My::Apache::Handler; use base qw( My::Apache::Request ); use Apache::Constants qw( :common :response ); sub handler { my $r = shift; $r->LOGGER->debug('Whatever'); $r->send_http_header(); print "The Handler.\n"; return OK; } 1;

If I comment out the $r->LOGGER line, it works OK, otherwise I get a "Can't locate object method" error.

Obviously, I'm not understanding either how to subclass an Apache::Request object properly, or my understanding on how mod_perl works is just not complete. Any ideas on what I'm doing wrong?

Update: Big thanks to everybody who's offered help on this one. I've learned so far that I have to unlearn everything I know about mod_perl. Maybe that will help me solve my problem. :)


In reply to Subclassing Apache::Request? by tadamec

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2024-04-25 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found