--- Devel-FindRef/FindRef.xs 2008/04/26 03:15:28 1.7 +++ Devel-FindRef/FindRef.xs 2008/04/27 05:59:06 1.8 @@ -13,24 +13,24 @@ #endif #define res_pair(text) \ - { \ + do { \ AV *av = newAV (); \ av_push (av, newSVpv (text, 0)); \ if (rmagical) SvRMAGICAL_on (sv); \ av_push (av, sv_rvweaken (newRV_inc (sv))); \ if (rmagical) SvRMAGICAL_off (sv); \ av_push (about, newRV_noinc ((SV *)av)); \ - } + } while (0) #define res_gv(sigil) \ - { \ + do { \ AV *av = newAV (); \ av_push (av, newSVpv (form ("in the global %c%s::%.*s", sigil, \ HvNAME (GvSTASH (sv)), \ GvNAMELEN (sv), GvNAME (sv) ? GvNAME (sv) : ""), \ 0)); \ av_push (about, newRV_noinc ((SV *)av)); \ - } + } while (0) MODULE = Devel::FindRef PACKAGE = Devel::FindRef @@ -121,7 +121,8 @@ { int depth = CvDEPTH (sv); - if (!depth && CvPADLIST(sv)) + /* Anonymous subs have a padlist but zero depth */ + if (!depth && CvPADLIST (sv)) depth = 1; if (depth) @@ -136,13 +137,24 @@ for (i = AvFILLp (pad) + 1; i--; ) if (AvARRAY (pad)[i] == targ) - res_pair (form ("in the lexical '%s' in", SvPVX (AvARRAY (AvARRAY (padlist)[0])[i]))); + { + /* Values from constant functions are stored in the pad without any name */ + SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; + + if (name_sv && SvPOK (name_sv)) + res_pair (form ("in the lexical '%s' in", SvPVX (name_sv))); + else + res_pair ("in an unnamed lexical in"); + } --depth; } } - if ((SV*)CvOUTSIDE(sv) == targ) + if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ) + res_pair ("the constant value of"); + + if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ) res_pair ("the containing scope for"); }