diff options
-rw-r--r-- | pp_ctl.c | 18 | ||||
-rw-r--r-- | t/op/require_errors.t | 1 |
2 files changed, 18 insertions, 1 deletions
@@ -4307,6 +4307,9 @@ S_require_file(pTHX_ SV *sv) SvSetSV_nosteal(nsv,sv); } + SV * inc_idx_sv = save_scalar(PL_incgv); + sv_setiv(inc_idx_sv,inc_idx); + ENTER_with_name("call_INC_hook"); SAVETMPS; EXTEND(SP, 2); @@ -4412,6 +4415,21 @@ S_require_file(pTHX_ SV *sv) /* FREETMPS may free our filter_cache */ SvREFCNT_inc_simple_void(filter_cache); + /* + Let the hook override which @INC entry we visit + next by setting $INC to a different value than it + was before we called the hook. If they have + completely rewritten the array they might want us + to start traversing from the beginning, which is + represented by -1. We use undef as an equivalent of + -1. This can't be used as a way to call a hook + twice, as we still dedupe. + We have to do this before we LEAVE, as we localized + $INC before we called the hook. + */ + inc_idx_sv = GvSVn(PL_incgv); + inc_idx = SvOK(inc_idx_sv) ? SvIV(inc_idx_sv) : -1; + PUTBACK; FREETMPS; LEAVE_with_name("call_INC_hook"); diff --git a/t/op/require_errors.t b/t/op/require_errors.t index 6ea300254f..849d57fc32 100644 --- a/t/op/require_errors.t +++ b/t/op/require_errors.t @@ -330,7 +330,6 @@ like $@, qr/^Can't locate \Q$nonsearch\E at/, { }, 'INC hooks that overwrite @INC continue as expected (skips a and z)'); } { - local $::TODO = "Pending new feature \$INC"; # as of 5.37.7 fresh_perl_like( '@INC = (sub { @INC=qw(a b); undef $INC }, "z"); ' |