summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2022-12-18 18:48:51 +0100
committerYves Orton <demerphq@gmail.com>2023-01-03 11:14:16 +0100
commit0d370d41c6e8fe1e36eb93a5561e6716ee3a7e3e (patch)
tree5ec09c9c1d512f71faa24d4bcf346561198886a3 /pp_ctl.c
parent46bcbc63da3e9dc034db2ae5bac841676313d183 (diff)
downloadperl-0d370d41c6e8fe1e36eb93a5561e6716ee3a7e3e.tar.gz
pp_ctl.c - Check if refs have overloads in @INC
If an object in @INC doesnt have a hook method, and it isnt a CODE ref then check if it has string overloading, if it does not then die with a helpful message, otherwise call the overload This uses the nice new amagic_find() function.
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index 07dd227b4f..e26ac219dc 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -4316,7 +4316,12 @@ S_require_file(pTHX_ SV *sv)
&& !SvOBJECT(SvRV(loader)))
{
loader = *av_fetch(MUTABLE_AV(SvRV(loader)), 0, TRUE);
- SvGETMAGIC(loader);
+ if (SvGMAGICAL(loader)) {
+ SvGETMAGIC(loader);
+ SV *l = sv_newmortal();
+ sv_setsv_nomg(l, loader);
+ loader = l;
+ }
}
if (SvPADTMP(nsv)) {
@@ -4357,10 +4362,18 @@ S_require_file(pTHX_ SV *sv)
*/
if (!method) {
if (SvTYPE(SvRV(loader)) != SVt_PVCV) {
- if (dirsv != loader)
- croak("Object with arguments in @INC does not support a hook method");
- else
+ if (amagic_applies(loader,string_amg,AMGf_unary))
goto treat_as_string;
+ else {
+ croak("Can't locate object method \"INC\", nor"
+ " \"INCDIR\" nor string overload via"
+ " package %" HvNAMEf_QUOTEDPREFIX " %s"
+ " in @INC", pkg,
+ dirsv == loader
+ ? "in object hook"
+ : "in object in ARRAY hook"
+ );
+ }
}
}
}
@@ -4379,11 +4392,6 @@ S_require_file(pTHX_ SV *sv)
if (method && (loader != dirsv)) /* add the args array for method calls */
PUSHs(dirsv);
PUTBACK;
- if (SvGMAGICAL(loader)) {
- SV *l = sv_newmortal();
- sv_setsv_nomg(l, loader);
- loader = l;
- }
if (method) {
count = call_method(method, G_LIST|G_EVAL);
} else {