Fatal::Exception - succeed or throw exception
use Fatal::Exception 'Exception::System' => qw< open close >; open FILE, "/nonexistent"; # throw Exception::System
use Exception::Base 'Exception::My'; sub juggle { ... } import Fatal::Exception 'Exception::My' => 'juggle'; juggle; # succeed or throw exception unimport Fatal::Exception 'juggle'; juggle or die; # restore original behavior
the Fatal::Exception manpage provides a way to conveniently replace functions which normally return a false value when they fail with equivalents which raise exceptions if they are not successful. This is the same as Fatal module but it throws the Exception::Base manpage object on error.
Replaces the original functions with wrappers which provide do-or-throw equivalents. You may wrap both user-defined functions and overridable CORE operators (except exec, system which cannot be expressed via prototypes) in this way.
If the symbol :void appears in the import list, then functions named later in that import list raise an exception only when these are called in void context.
You should not fatalize functions that are called in list context, because this module tests whether a function has failed by testing the boolean truth of its return value in scalar context.
If the exception class is not exist, its module is loaded with "use Exception" automatically.
Restores original functions for user-defined functions or replaces the functions with do-without-die wrappers for CORE operators.
In fact, the CORE operators cannot be restored, so the non-fatalized alternative is provided instead.
The functions can be wrapped and un-wrapped all the time.
The the Fatal::Exception manpage module was benchmarked with other implementations. The results are following:
--------------------------------------------------------------- | Module | Success | Failure | --------------------------------------------------------------- | eval/die | 263214/s | 234057/s | --------------------------------------------------------------- | Fatal | 98642/s | 8219/s | --------------------------------------------------------------- | Fatal::Exception | 129152/s | 4932/s | ---------------------------------------------------------------
the Fatal manpage, the Exception::Base manpage, the Exception::System manpage
The module was tested with the Test::Unit::Lite manpage and the Devel::Cover manpage.
If you find the bug, please report it.
Piotr Roszatycki <dexter@debian.org>
Copyright (C) 2007 by Piotr Roszatycki <dexter@debian.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.