5 use vars qw( $AUTOLOAD $Debug );
14 &_make_fatal($sym, $pkg);
21 &_make_fatal($cmd, (caller)[0]);
27 my($name, $code, $sref);
29 $sub = "${pkg}::$sub" unless $sub =~ /::/;
31 $name =~ s/.*::// or $name =~ s/^&//;
32 print "# _make_fatal: sub=$sub pkg=$pkg name=$name\n" if $Debug;
33 croak "Bad subroutine name for Fatal: $name" unless $name =~ /^\w+$/;
34 $code = "sub $name {\n\tlocal(\$\", \$!) = (', ', 0);\n";
41 $code .= "\tCORE::$name";
43 $code .= "\(\@_\) || croak \"Can't $name\(\@_\): \$!\";\n}\n";
44 print $code if $Debug;
47 local($^W) = 0; # to avoid: Subroutine foo redefined ...
48 no strict 'refs'; # to avoid: Can't use string (...) as a symbol ref ...
49 *{$sub} = \&{"Fatal::$name"};
58 Fatal - replace functions with equivalents which succeed or die
62 use Fatal qw(open print close);
65 import Fatal 'juggle';
69 C<Fatal> provides a way to conveniently replace functions which normally
70 return a false value when they fail with equivalents which halt execution
71 if they are not successful. This lets you use these functions without
72 having to test their return values explicitly on each call. Errors are
73 reported via C<die>, so you can trap them using C<$SIG{__DIE__}> if you
74 wish to take some action before the program exits.
76 The do-or-die equivalents are set up simply by calling Fatal's C<import>
77 routine, passing it the names of the functions to be replaced. You may
78 wrap both user-defined functions and CORE operators in this way.