summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gv.c3
-rw-r--r--t/op/magic.t21
2 files changed, 22 insertions, 2 deletions
diff --git a/gv.c b/gv.c
index 5ddfb563e8..f4176865a2 100644
--- a/gv.c
+++ b/gv.c
@@ -1239,7 +1239,8 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
if (add) {
GvMULTI_on(gv);
gv_init_sv(gv, sv_type);
- if (len == 1 && (sv_type == SVt_PVHV || sv_type == SVt_PVGV)) {
+ if (len == 1 && stash == PL_defstash
+ && (sv_type == SVt_PVHV || sv_type == SVt_PVGV)) {
if (*name == '!')
require_tie_mod(gv, "!", newSVpvs("Errno"), "TIEHASH", 1);
else if (*name == '-' || *name == '+')
diff --git a/t/op/magic.t b/t/op/magic.t
index 6951850e0f..6701cf77cf 100644
--- a/t/op/magic.t
+++ b/t/op/magic.t
@@ -12,7 +12,7 @@ BEGIN {
use warnings;
use Config;
-plan (tests => 83);
+plan (tests => 87);
$Is_MSWin32 = $^O eq 'MSWin32';
$Is_NetWare = $^O eq 'NetWare';
@@ -445,6 +445,25 @@ SKIP: {
ok ${"!"}{ENOENT};
}
+# Check that we don't auto-load packages
+foreach (['powie::!', 'Errno'],
+ ['powie::+', 'Tie::Hash::NamedCapture']) {
+ my ($symbol, $package) = @$_;
+ foreach my $scalar_first ('', '$$symbol;') {
+ my $desc = qq{Referencing %{"$symbol"}};
+ $desc .= qq{ after mentioning \${"$symbol"}} if $scalar_first;
+ $desc .= " doesn't load $package";
+
+ fresh_perl_is(<<"EOP", 0, {}, $desc);
+use strict qw(vars subs);
+my \$symbol = '$symbol';
+$scalar_first;
+1 if %{\$symbol};
+print scalar %${package}::;
+EOP
+ }
+}
+
is $^S, 0;
eval { is $^S,1 };
eval " BEGIN { ok ! defined \$^S } ";