This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid more vivification in Carp
authorZefram <zefram@fysh.org>
Thu, 22 Aug 2013 21:29:08 +0000 (22:29 +0100)
committerZefram <zefram@fysh.org>
Thu, 22 Aug 2013 21:33:23 +0000 (22:33 +0100)
Avoid vivifying the overload::StrVal subroutine, its glob, or its stash.
This is done in the same way as the existing avoidance of vivification of
utf8::is_utf8 and utf8::downgrade.  However, the check has to be made at
runtime, whereas the utf8-related ones are checked at load time, because
the utf8 ones are built into the perl core (only absent pre perl 5.8)
but overload is a separate module that can be loaded later.

dist/Carp/lib/Carp.pm
dist/Carp/t/vivify_gv.t
dist/Carp/t/vivify_stash.t
pod/perldelta.pod

index 44dc0fb..60df58f 100644 (file)
@@ -236,7 +236,11 @@ sub format_arg {
         }
         else
         {
-            $arg = defined(&overload::StrVal) ? overload::StrVal($arg) : "$arg";
+           no strict "refs";
+           $arg = exists($::{"overload::"}) &&
+                   exists(*{$::{"overload::"}}{HASH}->{"StrVal"}) &&
+                   defined(*{*{$::{"overload::"}}{HASH}->{"StrVal"}}{CODE}) ?
+               &{"overload::StrVal"}($arg) : "$arg";
         }
     }
     if ( defined($arg) ) {
index 3ed9912..62602a4 100644 (file)
@@ -1,11 +1,14 @@
-BEGIN { print "1..2\n"; }
+BEGIN { print "1..3\n"; }
 
 our $has_is_utf8; BEGIN { $has_is_utf8 = exists($utf8::{"is_utf8"}); }
 our $has_dgrade; BEGIN { $has_dgrade = exists($utf8::{"downgrade"}); }
+our $has_strval; BEGIN { $has_strval = exists($overload::{"StrVal"}); }
 
 use Carp;
+sub { Carp::longmess() }->(\1);
 
 print !(exists($utf8::{"is_utf8"}) xor $has_is_utf8) ? "" : "not ", "ok 1\n";
 print !(exists($utf8::{"downgrade"}) xor $has_dgrade) ? "" : "not ", "ok 2\n";
+print !(exists($overload::{"StrVal"}) xor $has_strval) ? "" : "not ", "ok 3\n";
 
 1;
index 7906748..226f960 100644 (file)
@@ -1,9 +1,12 @@
-BEGIN { print "1..1\n"; }
+BEGIN { print "1..2\n"; }
 
 our $has_utf8; BEGIN { $has_utf8 = exists($::{"utf8::"}); }
+our $has_overload; BEGIN { $has_overload = exists($::{"overload::"}); }
 
 use Carp;
+sub { Carp::longmess() }->(\1);
 
 print !(exists($::{"utf8::"}) xor $has_utf8) ? "" : "not ", "ok 1\n";
+print !(exists($::{"overload::"}) xor $has_overload) ? "" : "not ", "ok 2\n";
 
 1;
index 04d3516..cc9ba6d 100644 (file)
@@ -121,8 +121,10 @@ XXX
 
 L<Carp> has been upgraded from version 1.31 to 1.32.
 
-Carp now avoids some unwanted Unicode warnings on older Perls; doesn't
-affect behaviour with current Perl.
+Carp now won't vivify the C<overload::StrVal> glob or subroutine or the
+C<overload> stash.
+It also avoids some unwanted Unicode warnings on older Perls (which
+doesn't affect behaviour with current Perl).
 
 =item *