in reply to More then one AUTOLOAD in a class hierarchy.
This works but we loose the CONTENT of $AUTOLOAD coming in Parent::AUTOLOAD.
Then why not just set it?
I do something similar to this when i make proxy classes in IOC::Proxy. The proxy class catches the AUTOLOAD and allows you to log it (or whatever you want your proxy to do) and then passes it to the actual object it is proxying.$Parent::AUTOLOAD = $AUTOLOAD; $self->Parent::AUTOLOAD(@_);
Of course this way requires you to know what superclass you want to dispatch too. A more generic solution would involve going through the @ISA array and calling AUTOLOAD on each superclass (if they have an AUTOLOAD that is). The code might look something like this (note: this is highly untested)
Of course this would only go down one level of the tree, unless this code was included in the AUTOLOAD on each level of your object hierarchy. A recursive solution would start getting really hairy (as if this wasn't hairy enough).if (we can do something) { ... } else { no strict 'refs'; foreach my $super (@{'${class}::ISA"}) { my $method; if ($method = $super->can('AUTOLOAD')) { ${"${super}::AUTOLOAD"} = $AUTOLOAD; return $class->$method(@_); } } }
But now I ask you, is all this really worth it to save a little bit of repetitive typing by hand-making getters and setters?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: More then one AUTOLOAD in a class hierarchy.
by ced (Initiate) on Nov 11, 2004 at 19:18 UTC | |
by stvn (Monsignor) on Nov 11, 2004 at 22:57 UTC |