dynamo has asked for the wisdom of the Perl Monks concerning the following question:
I have an odd problem for you this morning. I am trying to implement a library system to make apache response handlers easier to get cranked out.
The idea is that the superclass has the actual handler() sub that apache calls, and it calls two basically empty subs in itself during it's handler call - one for config info, and one for the actual handler (but it's named something other than handler). The subclasses inherit all three subs I just mentioned from the parent class, and they are supposed to override the two empty ones with information that gets their job done, and allows me to factor out the common elements into the base class.
It looks something like this in the parent class:
sub handler { my $r = shift; my $err = ErrorTracker->new; # ... setup stuff my $args = validate_args($r, wrapped_handler_args()); $r->content_type('text/plain'); eval(wrapped_handler($r,$args,$err)); print $err->dumpHtml if $@; # shutdown / error handling stuff return $err->apacheStatus(); } sub wrapped_handler { print "inheritance is broken"; } sub wrapped_handler_args { return {}; }
Using @ISA works when apache calls the child class's missing handler() 'method', even though there's no object / $self being passed around at that point. It works well enough to be calling the base class's handler properly - apparently it 's fine with just rerouting subroutine calls in an OO manner regardless of arguments used.
Here's the problem. I am finding that the parent class can't access the child class because I am losing it's class name when perl does the @ISA search. I can't control the way mod_perl is calling the handler (or at least I don't want to for this project, I enjoy using a stock mod_perl.)
All I need is a way to find out what the class that originally got called before @ISA got involved. I am trying to avoid resorting to a hardwired routing table in the code, when the class name should be available to the runtime environment.
Is there such a way?
Maybe in some undocumented method of the apache request rec?
Or in some obscure perl system variable in the inheritance mechanism?
Or, if I had a variable like $AUTOLOAD (inside the AUTOLOAD subroutine) available to tell me the class that apache actually originally called, that would work. But I tried it, and it's not there for me when I need it.
I plead for enlightenment. Any hints or past experiences also welcome.
Thank you.
PS - For the record, adding an object to pass around doesn't solve the original problem - and I'm not opposed to it - but I still need to create said object inside of the handler() call of the base class. And it wasn't called in an object oriented context, so I don't know the class to create it as.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Class Inheritance without an instance
by dave_the_m (Monsignor) on Oct 13, 2005 at 11:32 UTC | |
by dynamo (Chaplain) on Oct 13, 2005 at 11:43 UTC | |
by dave_the_m (Monsignor) on Oct 13, 2005 at 11:58 UTC | |
by dynamo (Chaplain) on Oct 13, 2005 at 12:07 UTC | |
by dave_the_m (Monsignor) on Oct 13, 2005 at 12:24 UTC | |
by Perl Mouse (Chaplain) on Oct 13, 2005 at 12:00 UTC | |
by dynamo (Chaplain) on Oct 13, 2005 at 11:57 UTC | |
|
Re: Class Inheritance without an instance / $AUTOLOAD equ
by friedo (Prior) on Oct 13, 2005 at 15:21 UTC | |
by dynamo (Chaplain) on Oct 13, 2005 at 17:46 UTC | |
| |
|
Re: Class Inheritance without an instance / $AUTOLOAD equ
by rinceWind (Monsignor) on Oct 13, 2005 at 12:05 UTC |