develooper Front page | perl.perl5.porters | Postings from December 2001

[PATCH] Carp.pm caller_info returns wrong info for eval

Thread Next
From:
Robert Spier
Date:
December 19, 2001 14:14
Subject:
[PATCH] Carp.pm caller_info returns wrong info for eval
Message ID:
15393.4370.605214.548582@rls.cx

Patch adds a test for this part of the caller_info function that was
broken.

It also fixes the function so that it actually returns the eval
function, in a format similar to the way Carp did before the great
rewrite.

All tests that passed before still pass.

Patch is against latest perl-snap.

-R

--- lib/Carp.t      2001-12-19 13:36:42-08  1.1
+++ lib/Carp.t      2001-12-19 13:47:47-08
@@ -5,7 +5,7 @@
 
 use Carp qw(carp cluck croak confess);
 
-print "1..7\n";
+print "1..8\n";
 
 print "ok 1\n";
 
@@ -51,3 +51,8 @@
 
 print "ok 7\n";
 
+# test for caller_info API
+my $eval = "use Carp::Heavy; return Carp::caller_info(0);";
+my %info = eval($eval);
+print "not " if ($info{sub_name} ne "eval '$eval'");
+print "ok 8\n";


--- lib/Carp/Heavy.pm.orig      Wed Dec 19 13:34:52 2001
+++ lib/Carp/Heavy.pm   Wed Dec 19 13:46:58 2001
@@ -77,14 +77,14 @@
 # the sub/require/eval
 sub get_subname {
   my $info = shift;
-  if (defined($info->{eval})) {
-    my $eval = $info->{eval};
+  if (defined($info->{evaltext})) {
+    my $eval = $info->{evaltext};
     if ($info->{is_require}) {
       return "require $eval";
     }
     else {
       $eval =~ s/([\\\'])/\\$1/g;
-      return str_len_trim($eval, $MaxEvalLen);
+      return "eval '" . str_len_trim($eval, $MaxEvalLen) . "'";
     }
   }

-- 


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About