You are being very harsh on yourself. It looks like when a sub is referenced that doesn't exist autoload will only ever look in the current package. So when you are making subroutine call (as opposed to a method call) AUTOLOAD will only ever search for fred::die, which doesn't exist, hence the repeated calls to AUTOLOAD. Interesting.
If the call to the missing subroutine is made as a method call, AUTOLOAD will search the current package and then the packages listed in the @ISA array. To get this to work the handler has to be called as a method, e.g.
bruce:1:~/tmp $ cat p.pl
#!/usr/bin/perl
# vim: sw=4
#use strict;
#use warnings;
package bert;
sub die {
die @_;
}
package fred;
our @ISA = qw( bert );
our $DEFAULT_HANDLER = "die";
our $AUTOLOAD;
sub AUTOLOAD {
print STDERR "AUTOLOAD(@_) - $AUTOLOAD\n";
my $self = shift;
$self->$DEFAULT_HANDLER('died via indirection');
}
package main;
my $fred = fred->raise_exception("some test");
bruce:1:~/tmp $ ./p.pl
AUTOLOAD(fred some test) - fred::raise_exception
fred died via indirection at ./p.pl line 10.
bruce:1:~/tmp $
So how to make a package inherit from "CORE" ? |