From: Mark Fowler Date: Wed, 25 Jul 2012 14:59:10 +0000 (-0400) Subject: name the try, catch and finally blocks X-Git-Tag: Try-Tiny-0.15~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5c9d800f523278626ab0291b19d3789bca6d2467;p=p5sagit%2FTry-Tiny.git name the try, catch and finally blocks --- diff --git a/lib/Try/Tiny.pm b/lib/Try/Tiny.pm index f291b14..7e0ee47 100644 --- a/lib/Try/Tiny.pm +++ b/lib/Try/Tiny.pm @@ -11,6 +11,8 @@ our @EXPORT = our @EXPORT_OK = qw(try catch finally); use Carp; $Carp::Internal{+__PACKAGE__}++; +BEGIN { eval "use Sub::Name; 1" or *{subname} = sub {1} } + # Need to prototype as @ not $$ because of the way Perl evaluates the prototype. # Keeping it at $$ means you only ever get 1 sub because we need to eval in a list # context & not a scalar one @@ -47,6 +49,11 @@ sub try (&;@) { # not perfect, but we could provide a list of additional errors for # $catch->(); + # name the blocks if we have Sub::Name installed + subname("try {...}" => $try); + subname("catch {...} " => $catch) if $catch; + subname("finally {...} " => $_) foreach @finally; + # save the value of $@ so we can set $@ back to it in the beginning of the eval # and restore $@ after the eval finishes my $prev_error = $@;