From: Chip Salzenberg Date: Tue, 18 Feb 1997 01:22:00 +0000 (+1200) Subject: [shell changes from patch from perl5.003_26 to perl5.003_27] X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9d17b0a6244cecb9ba7d42c6a1a882fd933f6f45;p=p5sagit%2Fp5-mst-13.2.git [shell changes from patch from perl5.003_26 to perl5.003_27] Change from running these commands: # this never worked anyway rm -f lib/Fatal.pm rm -f t/lib/fatal.t # ready to patch exit 0 --- diff --git a/lib/Fatal.pm b/lib/Fatal.pm deleted file mode 100644 index 281474c..0000000 --- a/lib/Fatal.pm +++ /dev/null @@ -1,82 +0,0 @@ -package Fatal; - -use Carp; -use strict; -use vars qw( $AUTOLOAD $Debug ); - -$Debug = 0; - -sub import { - my $self = shift(@_); - my($sym, $pkg); - $pkg = (caller)[0]; - foreach $sym (@_) { - &_make_fatal($sym, $pkg); - } -}; - -sub AUTOLOAD { - my $cmd = $AUTOLOAD; - $cmd =~ s/.*:://; - &_make_fatal($cmd, (caller)[0]); - goto &$AUTOLOAD; -} - -sub _make_fatal { - my($sub, $pkg) = @_; - my($name, $code, $sref); - - $sub = "${pkg}::$sub" unless $sub =~ /::/; - $name = $sub; - $name =~ s/.*::// or $name =~ s/^&//; - print "# _make_fatal: sub=$sub pkg=$pkg name=$name\n" if $Debug; - croak "Bad subroutine name for Fatal: $name" unless $name =~ /^\w+$/; - $code = "sub $name {\n\tlocal(\$\", \$!) = (', ', 0);\n"; - if (defined(&$sub)) { - # user subroutine - $sref = \&$sub; - $code .= "\t&\$sref"; - } else { - # CORE subroutine - $code .= "\tCORE::$name"; - } - $code .= "\(\@_\) || croak \"Can't $name\(\@_\): \$!\";\n}\n"; - print $code if $Debug; - eval($code); - die if $@; - local($^W) = 0; # to avoid: Subroutine foo redefined ... - no strict 'refs'; # to avoid: Can't use string (...) as a symbol ref ... - *{$sub} = \&{"Fatal::$name"}; -} - -1; - -__END__ - -=head1 NAME - -Fatal - replace functions with equivalents which succeed or die - -=head1 SYNOPSIS - - use Fatal qw(open print close); - - sub juggle { . . . } - import Fatal 'juggle'; - -=head1 DESCRIPTION - -C provides a way to conveniently replace functions which normally -return a false value when they fail with equivalents which halt execution -if they are not successful. This lets you use these functions without -having to test their return values explicitly on each call. Errors are -reported via C, so you can trap them using C<$SIG{__DIE__}> if you -wish to take some action before the program exits. - -The do-or-die equivalents are set up simply by calling Fatal's C -routine, passing it the names of the functions to be replaced. You may -wrap both user-defined functions and CORE operators in this way. - -=head1 AUTHOR - -Lionel.Cons@cern.ch diff --git a/t/lib/fatal.t b/t/lib/fatal.t deleted file mode 100755 index fe2f63d..0000000 --- a/t/lib/fatal.t +++ /dev/null @@ -1,23 +0,0 @@ -#!./perl - -BEGIN { - chdir 't' if -d 't'; - @INC = '../lib'; -} - -print "1..2\n"; - -sub false { 0; } - -sub true { 1; } - -use Fatal qw(true false); - -eval { true(); }; - -print "not " if $@; -print "ok 1\n"; - -eval { false(); }; -print "not " unless $@; -print "ok 2\n";