Sub::ForceEval

Eval subroutines, re-throw exceptions if there is an eval; otherwise cluck and return undef
Download

Sub::ForceEval Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Steven Lembark
  • Publisher web site:
  • http://search.cpan.org/~lembark/

Sub::ForceEval Tags


Sub::ForceEval Description

Eval subroutines, re-throw exceptions if there is an eval; otherwise cluck and return undef Subroutines that are marked with the ForceEval attribute check at runtime if there is an eval on the stack when the call dies. If an eval is found then the die is propagated to it via die $@; if not then cluck (see Carp) is called and the die is trapped.The stack is only checked if something dies, so there is relatively little overhead in using the attribute: just an eval and intermediate storage of the return values.Note that this inludes anything that dies for any reason even if the death is not intended as an OO 'exception'. This can be helpful for long-lived processes that need to ensure survival. It can also be handy for subs that call modules which use Fatal: all of the fatalities can be guaranteed to be gracefully handled.If exception objects are preferred to flat $@ values then a constructor can be provided with the use. This will be broken into class and method portions and called to construct an object from the exception; individual subs can also provide a constructor.Sub::ForceEval is a Perl module for eval subroutines, re-throw exceptions if there is an eval; otherwise cluck and return undef.SYNOPSIS # you may just want your death recorded... # # if foo dies in an eval then $@ will be re-thrown, # otherwise foo will cluck, return undef, and keep # going. use Sub::ForceEval; sub foo :ForceEval { ... } # a bare call to foo() in the main code will cluck. foo(); # the exception is re-thrown here, however, since # bletch was called from within an eval. eval { bletch() }; sub bletch { bar() } sub bar { foo() } # ... or you may want an exceptional death. # # the default in MyClass is to have ForceEval # call My::Class::Default- >constructor( $@ ) # before re-throwing, marine re-throws # Dive::Dive- >dive( $@ ). package MyClass; use Sub::ForceEval qw( My::Class::Default- >constructor ); sub marine :ForceEval( 'Dive::Dive- >dive' ); # then again, you may just want to record or # tidy up the message. in this case, you can pass # in a function without the '- >' separator and # it'll be callsed as function( $@ ). use Sub::ForceEval qw( Some::Package::function ); Requirements: · Perl


Sub::ForceEval Related Software