http://qs321.pair.com?node_id=381826

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

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. :)