This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Carp's argument backtrace code would show undef as "undef" - a string.
authorNicholas Clark <nick@ccl4.org>
Wed, 12 Sep 2007 23:11:45 +0000 (23:11 +0000)
committerNicholas Clark <nick@ccl4.org>
Wed, 12 Sep 2007 23:11:45 +0000 (23:11 +0000)
p4raw-id: //depot/perl@31858

lib/Carp.pm
lib/Carp.t
lib/Carp/Heavy.pm

index 52ccd76..393b126 100644 (file)
@@ -1,6 +1,6 @@
 package Carp;
 
 package Carp;
 
-our $VERSION = '1.07';
+our $VERSION = '1.08';
 # this file is an utra-lightweight stub. The first time a function is
 # called, Carp::Heavy is loaded, and the real short/longmessmess_jmp
 # subs are installed
 # this file is an utra-lightweight stub. The first time a function is
 # called, Carp::Heavy is loaded, and the real short/longmessmess_jmp
 # subs are installed
index 63e1565..c24760b 100644 (file)
@@ -8,7 +8,7 @@ my $Is_VMS = $^O eq 'VMS';
 
 use Carp qw(carp cluck croak confess);
 
 
 use Carp qw(carp cluck croak confess);
 
-plan tests => 36;
+plan tests => 37;
 
 ok 1;
 
 
 ok 1;
 
@@ -254,6 +254,18 @@ sub w { cluck @_ }
     is($?>>8, 42, 'confess() doesn\'t clobber $!');
 }
 
     is($?>>8, 42, 'confess() doesn\'t clobber $!');
 }
 
+# undef used to be incorrectly reported as the string "undef"
+sub cluck_undef {
+
+local $SIG{__WARN__} = sub {
+    like $_[0], qr/^Bang! at.+\b(?i:carp\.t) line \d+\n\tmain::cluck_undef\(0, 'undef', 2, undef, 4\) called at.+\b(?i:carp\.t) line \d+$/, "cluck doesn't quote undef" };
+
+cluck "Bang!"
+
+}
+
+cluck_undef (0, "undef", 2, undef, 4);
+
 # line 1 "A"
 package A;
 sub short {
 # line 1 "A"
 package A;
 sub short {
index 15f8188..91d6ab1 100644 (file)
@@ -104,14 +104,16 @@ sub format_arg {
   my $arg = shift;
   if (ref($arg)) {
       $arg = defined($overload::VERSION) ? overload::StrVal($arg) : "$arg";
   my $arg = shift;
   if (ref($arg)) {
       $arg = defined($overload::VERSION) ? overload::StrVal($arg) : "$arg";
-  }elsif (not defined($arg)) {
-    $arg = 'undef';
   }
   }
-  $arg =~ s/'/\\'/g;
-  $arg = str_len_trim($arg, $MaxArgLen);
+  if (defined($arg)) {
+      $arg =~ s/'/\\'/g;
+      $arg = str_len_trim($arg, $MaxArgLen);
   
   
-  # Quote it?
-  $arg = "'$arg'" unless $arg =~ /^-?[\d.]+\z/;
+      # Quote it?
+      $arg = "'$arg'" unless $arg =~ /^-?[\d.]+\z/;
+  } else {
+      $arg = 'undef';
+  }
 
   # The following handling of "control chars" is direct from
   # the original code - it is broken on Unicode though.
 
   # The following handling of "control chars" is direct from
   # the original code - it is broken on Unicode though.