in reply to Re: Problem using code ref's in AUTOLOAD
in thread Problem using code ref's in AUTOLOAD

Mmm, OK, looks like I'm being way dense ... you're right WRT code ref's, however, it doesn't explain why a call of the form
package fred; our $DEFAULT_HANDLER = 'die'; sub AUTOLOAD { $&ref("Some text"); }
doesn't work ... or my ignorance exceeds even my normal standards, and it does ?

Replies are listed 'Best First'.
Re^3: Problem using code ref's in AUTOLOAD
by bruceb3 (Pilgrim) on Aug 28, 2007 at 10:30 UTC

    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" ?