Permalink
Browse files

[perl #105024] UNIVERSAL::AUTOLOAD and %+

The code in gv.c for loading a tie module automatically
(S_require_tie_mod) was only loading the module if its stash did not
exist or if a particular method (usually TIEHASH) could not be found.
But it was triggering autoloading, such that a universal AUTOLOAD
method would allow it to ‘find’ the method it was looking for, even if
it did not exist.  So autovivifying the package somehow (e.g., by men-
tioning one of its symbols) could prevent the module from loading.
  • Loading branch information...
1 parent c624397 commit 0ea03996e7eb3b3be4ed648a954c083fc011f523 Father Chrysostomos committed Dec 1, 2011
Showing with 20 additions and 2 deletions.
  1. +1 −1 gv.c
  2. +19 −1 t/op/magic.t
View
2 gv.c
@@ -1267,7 +1267,7 @@ S_require_tie_mod(pTHX_ GV *gv, const char *varpv, SV* namesv, const char *methp
PERL_ARGS_ASSERT_REQUIRE_TIE_MOD;
- if (!stash || !(gv_fetchmethod(stash, methpv))) {
+ if (!stash || !(gv_fetchmethod_autoload(stash, methpv, FALSE))) {
SV *module = newSVsv(namesv);
char varname = *varpv; /* varpv might be clobbered by load_module,
so save it. For the moment it's always
View
@@ -5,7 +5,7 @@ BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
- plan (tests => 147);
+ plan (tests => 150);
}
# Test that defined() returns true for magic variables created on the fly,
@@ -529,6 +529,24 @@ foreach my $sig (qw(__DIE__ _BOGUS_HOOK KILL THIRSTY)) {
}
+SKIP: {
+ skip_if_miniperl("No XS in miniperl", 3);
+
+ for ( [qw( %- Tie::Hash::NamedCapture )], [qw( $[ arybase )],
+ [qw( %! Errno )] ) {
+ my ($var, $mod) = @$_;
+ my $modfile = $mod =~ s|::|/|gr . ".pm";
+ fresh_perl_is
+ qq 'sub UNIVERSAL::AUTOLOAD{}
+ $mod\::foo() if 0;
+ $var;
+ print "ok\\n" if \$INC{"$modfile"}',
+ "ok\n",
+ { switches => [ '-X' ] },
+ "$var still loads $mod when stash and UNIVERSAL::AUTOLOAD exist";
+ }
+}
+
# ^^^^^^^^^ New tests go here ^^^^^^^^^
SKIP: {

0 comments on commit 0ea0399

Please sign in to comment.