in reply to AUTOLOAD and inheritance
I see two problems. The small problem is that $AUTOLOAD contains the name of the class, so you have to strip that off first.
The big problem is that it appears the inheritance is working before AUTOLOAD gets a chance to run. One way around this, which is pretty ugly, is to avoid setting up the inheritence until AUTOLOAD is run. I'm not sure how workable this solution is, but at least it's something to chew on.
You can see this by changing AA.pm to:
package AA; require BB; sub AUTOLOAD { my ($self,$extrainfo,@args) = @_; local @ISA = 'BB'; my ($method) = (split /::/, $AUTOLOAD)[-1]; $superfunk = "SUPER::$method"; $self->$superfunk(@args); } 1;
Update: an alternative way to accomplish a similar goal, without using AUTOLOAD, would go something like this:
package AA; use base 'BB'; for my $meth (qw(print flop frizzle)) { *{ $meth } = sub { my ($self, $extra, @args) = @_; my $meth = "SUPER::$meth"; $self->$meth(@args); }; } 1;
Which just goes to show that AUTOLOAD is not the only way to dynamically create methods.
|
|---|