X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FFatal.pm;h=d1d95af884854fc489c78f4af04b50830f78daaa;hb=26f2972e6cc14b5198456611d023553a813ccb68;hp=0d9c51b113c89ed62b316a49b495824c7ae33788;hpb=902662995003194c4ae9313f14d74b42cf7e4963;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Fatal.pm b/lib/Fatal.pm index 0d9c51b..d1d95af 100644 --- a/lib/Fatal.pm +++ b/lib/Fatal.pm @@ -2,9 +2,11 @@ package Fatal; use Carp; use strict; -use vars qw( $AUTOLOAD $Debug ); +use vars qw( $AUTOLOAD $Debug $VERSION); -$Debug = 0; +$VERSION = 1.02; + +$Debug = 0 unless defined $Debug; sub import { my $self = shift(@_); @@ -22,31 +24,100 @@ sub AUTOLOAD { goto &$AUTOLOAD; } +sub fill_protos { + my $proto = shift; + my ($n, $isref, @out, @out1, $seen_semi) = -1; + while ($proto =~ /\S/) { + $n++; + push(@out1,[$n,@out]) if $seen_semi; + push(@out, $1 . "{\$_[$n]}"), next if $proto =~ s/^\s*\\([\@%\$\&])//; + push(@out, "\$_[$n]"), next if $proto =~ s/^\s*([*\$&])//; + push(@out, "\@_[$n..\$#_]"), last if $proto =~ s/^\s*(;\s*)?\@//; + $seen_semi = 1, $n--, next if $proto =~ s/^\s*;//; # XXXX ???? + die "Unknown prototype letters: \"$proto\""; + } + push(@out1,[$n+1,@out]); + @out1; +} + +sub write_invocation { + my ($core, $call, $name, @argvs) = @_; + if (@argvs == 1) { # No optional arguments + my @argv = @{$argvs[0]}; + shift @argv; + return "\t" . one_invocation($core, $call, $name, @argv) . ";\n"; + } else { + my $else = "\t"; + my (@out, @argv, $n); + while (@argvs) { + @argv = @{shift @argvs}; + $n = shift @argv; + push @out, "$ {else}if (\@_ == $n) {\n"; + $else = "\t} els"; + push @out, + "\t\treturn " . one_invocation($core, $call, $name, @argv) . ";\n"; + } + push @out, <, 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. +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 overridable +CORE operators (except C, C which cannot be expressed +via prototypes) in this way. =head1 AUTHOR Lionel.Cons@cern.ch + +prototype updates by Ilya Zakharevich ilya@math.ohio-state.edu + +=cut