diff options
author | Tony Cook <tony@develop-help.com> | 2023-02-02 15:15:04 +1100 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2023-02-08 13:42:50 +1100 |
commit | 626df4fd56759528a170e821cab27f372b174496 (patch) | |
tree | a8712418609e1d7a24f54d47cb4514e475037c36 | |
parent | 0de69e372d3baf843522c30d8711b6513c2a472b (diff) | |
download | perl-626df4fd56759528a170e821cab27f372b174496.tar.gz |
allow AUTOLOAD for the INC method of objects in @INC
This matches the behaviour in 5.36.
This does not allow AUTOLOAD for INCDIR, since if there is an AUTOLOAD
the check for INC would have already succeeded.
Fixes #20665
-rw-r--r-- | pp_ctl.c | 3 | ||||
-rw-r--r-- | t/op/inccode.t | 22 |
2 files changed, 23 insertions, 2 deletions
@@ -4338,10 +4338,11 @@ S_require_file(pTHX_ SV *sv) * call the method. */ HV *pkg = SvSTASH(SvRV(loader)); - GV * gv = gv_fetchmethod_pvn_flags(pkg, "INC", 3, 0); + GV * gv = gv_fetchmethod_pvn_flags(pkg, "INC", 3, GV_AUTOLOAD); if (gv && isGV(gv)) { method = "INC"; } else { + /* no point to autoload here, it would have been found above */ gv = gv_fetchmethod_pvn_flags(pkg, "INCDIR", 6, 0); if (gv && isGV(gv)) { method = "INCDIR"; diff --git a/t/op/inccode.t b/t/op/inccode.t index 26b6993f29..ef124f3eb3 100644 --- a/t/op/inccode.t +++ b/t/op/inccode.t @@ -21,7 +21,7 @@ unless (is_miniperl()) { use strict; -plan(tests => 68 + !is_miniperl() * (4 + 14 * $can_fork)); +plan(tests => 71 + !is_miniperl() * (4 + 14 * $can_fork)); sub get_temp_fh { my $f = tempfile(); @@ -179,6 +179,26 @@ is( $INC{'Toto.pm'}, 'xyz', ' val Toto.pm is correct in %INC' ); pop @INC; +{ + my $autoloaded; + package AutoInc { + sub AUTOLOAD { + my ($self, $filename) = @_; + $autoloaded = our $AUTOLOAD; + return ::get_temp_fh($filename); + } + sub DESTROY {} + } + + push @INC, bless {}, "AutoInc"; + $evalret = eval { require Quux3; 1 }; + ok($evalret, "require Quux3 via AUTOLOADed INC"); + ok(exists $INC{"Quux3.pm"}, "Quux3 in %INC"); + is($autoloaded, "AutoInc::INC", "AUTOLOAD was called for INC"); + + pop @INC; +} + push @INC, sub { my ($self, $filename) = @_; if ($filename eq 'abc.pl') { |