Bloodnok has asked for the wisdom of the Perl Monks concerning the following question:
I'm having loads'o trouble calling functions using code ref's from with an AUTOLOAD method - I have a package that should have a configurable way of handling exceptions - configuration being via the selection of a function from the standard functions e.g. die() or croak(), such that AUTOLOAD should cause a die() or croak() (or whatsoever) as appropriate. Assuming (in its simplest form), a package as follows ...
and a call such as ...package fred; use Carp; our $DEFAULT_HANDLER = 'die'; . . or . our $DEFAULT_HANDLER = \¨ our $AUTOLOAD; sub AUTOLOAD { print STDERR "AUTOLOAD(@_) - $AUTOLOAD\n"; my $self = shift(); $DEFAULT_HANDLER-<('Died via indirection'); # a la Schwarz & Phoe +nix &$DEFAULT_HANDLER('Died via default'); }
If either or both the definition of $DEFAULT_HANDLER and the call to the referenced function are changed, the problem continues to manifest itself as follows ...fred->raise_exception("Some text");
The reference gets converted to the configured function call and then the search begins again for a method belonging to the package i.e. at no time does the configured function get called !! I'm using Strawberry perl on Win2K. Am I being spectacularly dense and missing something so obvious it's untrue, or is/may there be a problem ? Anybody any ideas ?? TIA ,AUTOLOAD(fred Some text) - fred::raise_exception AUTOLOAD(Some text) - fred::die
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem using code ref's in AUTOLOAD
by bruceb3 (Pilgrim) on Aug 27, 2007 at 21:59 UTC | |
by Bloodnok (Vicar) on Aug 28, 2007 at 09:03 UTC | |
by bruceb3 (Pilgrim) on Aug 28, 2007 at 10:30 UTC |