summaryrefslogtreecommitdiff
path: root/dist
diff options
context:
space:
mode:
authorZefram <zefram@fysh.org>2013-08-22 22:29:08 +0100
committerZefram <zefram@fysh.org>2013-08-22 22:33:23 +0100
commitbd098b9ac583eefaa2df23e3b12fcae8a50321db (patch)
tree0bcb0a741c1033969adb74d3ca2836ffc3b33976 /dist
parent91efe593b9fc36e1b11b94485a57ad03ae416cce (diff)
downloadperl-bd098b9ac583eefaa2df23e3b12fcae8a50321db.tar.gz
avoid more vivification in Carp
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.
Diffstat (limited to 'dist')
-rw-r--r--dist/Carp/lib/Carp.pm6
-rw-r--r--dist/Carp/t/vivify_gv.t5
-rw-r--r--dist/Carp/t/vivify_stash.t5
3 files changed, 13 insertions, 3 deletions
diff --git a/dist/Carp/lib/Carp.pm b/dist/Carp/lib/Carp.pm
index 44dc0fbfb3..60df58ff1b 100644
--- a/dist/Carp/lib/Carp.pm
+++ b/dist/Carp/lib/Carp.pm
@@ -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) ) {
diff --git a/dist/Carp/t/vivify_gv.t b/dist/Carp/t/vivify_gv.t
index 3ed9912093..62602a4e88 100644
--- a/dist/Carp/t/vivify_gv.t
+++ b/dist/Carp/t/vivify_gv.t
@@ -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;
diff --git a/dist/Carp/t/vivify_stash.t b/dist/Carp/t/vivify_stash.t
index 7906748a4f..226f960446 100644
--- a/dist/Carp/t/vivify_stash.t
+++ b/dist/Carp/t/vivify_stash.t
@@ -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;