X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Findirect.git;a=blobdiff_plain;f=indirect.xs;h=3bd5e6cef5addca2a46f23de0f07979c1152d5dc;hp=78788021af885ab2c1afaf3804c919fcd9e7f8f5;hb=07fb4eb28539b53578b1421e348c12c921d180f1;hpb=faa0984a60b4134d0556ed7e6225bf83ddfb5474 diff --git a/indirect.xs b/indirect.xs index 7878802..3bd5e6c 100644 --- a/indirect.xs +++ b/indirect.xs @@ -576,6 +576,25 @@ STATIC OP *indirect_ck_const(pTHX_ OP *o) { STRLEN pos; if (indirect_find(sv, PL_oldbufptr, &pos)) { + STRLEN len; + + /* If the constant is equal to the current package name, try to look for + * a "__PACKAGE__" coming before what we got. We only need to check this + * when we already had a match because __PACKAGE__ can only appear in + * direct method calls ("new __PACKAGE__" is a syntax error). */ + len = SvCUR(sv); + if (len == HvNAMELEN_get(PL_curstash) + && memcmp(SvPVX(sv), HvNAME_get(PL_curstash), len) == 0) { + STRLEN pos_pkg; + SV *pkg = sv_newmortal(); + sv_setpvn(pkg, "__PACKAGE__", sizeof("__PACKAGE__")-1); + + if (indirect_find(pkg, PL_oldbufptr, &pos_pkg) && pos_pkg < pos) { + sv = pkg; + pos = pos_pkg; + } + } + indirect_map_store(o, pos, sv, CopLINE(&PL_compiling)); return o; }