in reply to Problem using code ref's in AUTOLOAD
... Even though it looks like a regular function call, it isn't: you can't take a reference to it, such as the incorrect "\&CORE::open" might appear to produce. ...
To get around this you could use an anonymous subroutine as the value to $DEFAULT_HANDLER.
our $DEFAULT_HANDLER = sub { die @_ };
Making this change seems to work.
bruce:1:~/tmp $ cat p.pl #!/usr/bin/perl # vim: sw=4 use strict; use warnings; package fred; our $DEFAULT_HANDLER = sub { die @_ }; our $AUTOLOAD; sub AUTOLOAD { print STDERR "AUTOLOAD(@_) - $AUTOLOAD\n"; my $self = shift; $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 died via indirection at ./p.pl line 9. bruce:1:~/tmp $
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem using code ref's in AUTOLOAD
by Bloodnok (Vicar) on Aug 28, 2007 at 09:03 UTC | |
by bruceb3 (Pilgrim) on Aug 28, 2007 at 10:30 UTC |