in reply to How to call AUTOLOAD before @ISA?
Like this:
Sometimes a strategy like delegation works better than inheritance, particularly when you're trying to "catch" every method call to an object. Another option might be using a tied object, similarly to how I used it in Tie: Creating special objects.package A; sub new { my $class = shift; bless {}, $class; } sub doit { print "doit in A\n"; } package B; sub new { my $class = shift; bless { a => new A }, $class; } sub AUTOLOAD { my $self = shift; ## Your debugging message. print "autoload in B, called as $AUTOLOAD\n"; return if $AUTOLOAD =~ /::DESTROY$/; ## Remove the name of your package. $AUTOLOAD =~ s/^B:://; ## Call the method on your A object. $self->{a}->$AUTOLOAD(@_); } package main; my $b = B->new; $b->doit;
|
|---|