Error Reporting on AUTOLOAD Failure

I use AUTOLOADundefined to handle calls for some routines.

sub AUTOLOAD {
    my $member = $AUTOLOAD;
    # ... do something if knowing how to handle '$member'        

    # otherwise ?
}

When calling a nonexistent subroutine (say my_method) on a package, Perl usually says something like

Can't locate object method "my_method" via package "MyPackage" 
at Package.pm line 99.

I want Perl to display this standard message if I don't know how to handle the subroutine call $memberin my implementation AUTOLOAD.

How can i do this?

I did not find a special variable that could contain the corresponding message. In addition, the Perl startup documentation does not give any hint of this problem.

Note: I would like to avoid overwriting the error message, but instead use the standard message provided by Perl.

+4
2

, . , @ISA , , UNIVERSAL. , AUTOLOAD . , perl , - . perl AUTOLOAD sub, AUTOLOAD.

, , - AUTOLOAD .

, :

sub AUTOLOAD {
    my ($package, $method) = $AUTOLOAD =~ /^(.*)::([^:]*)/;
    die sprintf(qq{Can't locate object method "%s" via package "%s" at %s line %d.\n}, 
            $method, $package, (caller)[1,2]);
}
+3

, . Carp :

sub AUTOLOAD {
    our $AUTOLOAD;
    my ($package,$method) = $AUTOLOAD=~/^(.*)::(.*)/s;
    use Carp ();
    local $Carp::CarpLevel = 1;
    Carp::croak( qq!Can't locate object method "$method" via package "$package"! );
}
+4

All Articles