diff options
author | Brian Fraser <fraserbn@gmail.com> | 2013-05-13 16:37:22 -0300 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2013-06-09 14:26:51 -0700 |
commit | 79f8d0e810e1442ce47a0b1e112c5f2b83d637a2 (patch) | |
tree | 6101a87ea6c132e5d3683f982b4c4fdec904c24f /dist/Carp | |
parent | 1a4f8f41aa38eebfdff591e350c60fd1832af3fb (diff) | |
download | perl-79f8d0e810e1442ce47a0b1e112c5f2b83d637a2.tar.gz |
Carp: Don't autovivify the CARP_NOT or ISA array
In this situation:
use Carp;
package Foo;
$CARP_NOT = 1;
warn *{$Foo::{CARP_NOT}}{ARRAY} || 'undefined';
eval { Carp::croak(1) };
warn *{$Foo::{CARP_NOT}}{ARRAY} || 'undefined';
The second warn shows that Carp is autovivifying the ARRAY slot
of the glob. This commit builds on the previous and checks that
the array exists before trying to use it.
Diffstat (limited to 'dist/Carp')
-rw-r--r-- | dist/Carp/lib/Carp.pm | 4 | ||||
-rw-r--r-- | dist/Carp/t/Carp.t | 10 |
2 files changed, 11 insertions, 3 deletions
diff --git a/dist/Carp/lib/Carp.pm b/dist/Carp/lib/Carp.pm index 6162177a5a..bb557ddf00 100644 --- a/dist/Carp/lib/Carp.pm +++ b/dist/Carp/lib/Carp.pm @@ -435,8 +435,8 @@ sub trusts_directly { for my $var (qw/ CARP_NOT ISA /) { # Don't try using the variable until we know it exists, # to avoid polluting the caller's namespace. - if ( $stash->{$var} && @{"$class\::$var"} ) { - return @{"$class\::$var"} + if ( $stash->{$var} && *{$stash->{$var}}{ARRAY} && @{$stash->{$var}} ) { + return @{$stash->{$var}} } } return; diff --git a/dist/Carp/t/Carp.t b/dist/Carp/t/Carp.t index 09c66524e0..f51bd113f8 100644 --- a/dist/Carp/t/Carp.t +++ b/dist/Carp/t/Carp.t @@ -3,7 +3,7 @@ no warnings "once"; use Config; use IPC::Open3 1.0103 qw(open3); -use Test::More tests => 62; +use Test::More tests => 63; sub runperl { my(%args) = @_; @@ -471,6 +471,14 @@ SKIP: [], "Carp doesn't create CARP_NOT or ISA in the caller if they don't exist" ); + + package Foo::No::Autovivify; + $CARP_NOT = 1; + eval { Carp::croak(1) }; + ::ok( + !defined *{$Foo::No::Autovivify::{CARP_NOT}}{ARRAY}, + "Carp doesn't autovivify the CARP_NOT or ISA arrays if the globs exists but they lack the ARRAY slot" + ); } # New tests go here |