diff options
author | tlhackque <tlhackque@yahoo.com> | 2011-12-15 20:48:21 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-12-15 21:38:02 -0800 |
commit | 89988fbd2f7d8a44526a3cd9ab671b3102898bc9 (patch) | |
tree | 7956ff3dcc67d537b212220b08ce3d7ce3b41685 /dist | |
parent | d47f310d69da3356f76ded4c14c2770d5f1325f4 (diff) | |
download | perl-89988fbd2f7d8a44526a3cd9ab671b3102898bc9.tar.gz |
Add missing <fh> line # phrase to Carp messages
Carp::croak is documented in the camel book as "working like die does,
except misdirecting blame to the caller."
Perldoc says "croak - die of errors (from perspective of caller)".
This is almost true, however careful inspection reveals that croak
does not include file position information ( ", <fh> line $." ) as die
does (when it can).
It turns out that it *is* possible to determine the current file han-
dle (although I wish it were easier).
Carp should do this and add it to the traceback, as it really is use-
ful information.
Diffstat (limited to 'dist')
-rw-r--r-- | dist/Carp/lib/Carp.pm | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/dist/Carp/lib/Carp.pm b/dist/Carp/lib/Carp.pm index 187cef496b..95503d3ff3 100644 --- a/dist/Carp/lib/Carp.pm +++ b/dist/Carp/lib/Carp.pm @@ -286,7 +286,17 @@ sub ret_backtrace { } my %i = caller_info($i); - $mess = "$err at $i{file} line $i{line}$tid_msg\n"; + $mess = "$err at $i{file} line $i{line}$tid_msg"; + if( defined $. ) { + local $@ = ''; + eval { + die; + }; + if($@ =~ /^Died at .*(, <.*?> line \d+).$/ ) { + $mess .= $1; + } + } + $mess .= "\n"; while ( my %i = caller_info( ++$i ) ) { $mess .= "\t$i{sub_name} called at $i{file} line $i{line}$tid_msg\n"; |