From 0d370d41c6e8fe1e36eb93a5561e6716ee3a7e3e Mon Sep 17 00:00:00 2001 From: Yves Orton Date: Sun, 18 Dec 2022 18:48:51 +0100 Subject: 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. --- pp_ctl.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'pp_ctl.c') 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 { -- cgit v1.2.1