… | |
… | |
10 | |
10 | |
11 | #if !PERL_VERSION_ATLEAST (5,8,9) |
11 | #if !PERL_VERSION_ATLEAST (5,8,9) |
12 | # define SVt_LAST 16 |
12 | # define SVt_LAST 16 |
13 | #endif |
13 | #endif |
14 | |
14 | |
|
|
15 | #if !PERL_VERSION_ATLEAST (5,10,0) |
|
|
16 | # define SvPAD_OUR(dummy) 0 |
|
|
17 | #endif |
|
|
18 | |
15 | #define res_pair(text) \ |
19 | #define res_pair(text) \ |
16 | { \ |
20 | do { \ |
17 | AV *av = newAV (); \ |
21 | AV *av = newAV (); \ |
18 | av_push (av, newSVpv (text, 0)); \ |
22 | av_push (av, newSVpv (text, 0)); \ |
19 | if (rmagical) SvRMAGICAL_on (sv); \ |
23 | if (rmagical) SvRMAGICAL_on (sv); \ |
20 | av_push (av, sv_rvweaken (newRV_inc (sv))); \ |
24 | av_push (av, sv_rvweaken (newRV_inc (sv))); \ |
21 | if (rmagical) SvRMAGICAL_off (sv); \ |
25 | if (rmagical) SvRMAGICAL_off (sv); \ |
22 | av_push (about, newRV_noinc ((SV *)av)); \ |
26 | av_push (about, newRV_noinc ((SV *)av)); \ |
23 | } |
27 | } while (0) |
24 | |
28 | |
25 | #define res_gv(sigil) \ |
29 | #define res_gv(sigil) \ |
26 | { \ |
30 | do { \ |
27 | AV *av = newAV (); \ |
31 | AV *av = newAV (); \ |
28 | av_push (av, newSVpv (form ("in the global %c%s::%.*s", sigil, \ |
32 | av_push (av, newSVpv (form ("in the global %c%s::%.*s", sigil, \ |
29 | HvNAME (GvSTASH (sv)), \ |
33 | HvNAME (GvSTASH (sv)), \ |
30 | GvNAMELEN (sv), GvNAME (sv) ? GvNAME (sv) : "<anonymous>"), \ |
34 | GvNAMELEN (sv), GvNAME (sv) ? GvNAME (sv) : "<anonymous>"), \ |
31 | 0)); \ |
35 | 0)); \ |
32 | av_push (about, newRV_noinc ((SV *)av)); \ |
36 | av_push (about, newRV_noinc ((SV *)av)); \ |
33 | } |
37 | } while (0) |
34 | |
38 | |
35 | MODULE = Devel::FindRef PACKAGE = Devel::FindRef |
39 | MODULE = Devel::FindRef PACKAGE = Devel::FindRef |
36 | |
40 | |
37 | PROTOTYPES: ENABLE |
41 | PROTOTYPES: ENABLE |
38 | |
42 | |
… | |
… | |
46 | void |
50 | void |
47 | find_ (SV *target) |
51 | find_ (SV *target) |
48 | PPCODE: |
52 | PPCODE: |
49 | { |
53 | { |
50 | SV *arena, *targ; |
54 | SV *arena, *targ; |
51 | int rmagical, i; |
55 | U32 rmagical; |
|
|
56 | int i; |
52 | AV *about = newAV (); |
57 | AV *about = newAV (); |
53 | AV *excl = newAV (); |
58 | AV *excl = newAV (); |
54 | |
59 | |
55 | if (!SvROK (target)) |
60 | if (!SvROK (target)) |
56 | croak ("find expects a reference to a perl value"); |
61 | croak ("find expects a reference to a perl value"); |
… | |
… | |
74 | if ((rmagical = SvRMAGICAL (sv))) |
79 | if ((rmagical = SvRMAGICAL (sv))) |
75 | SvRMAGICAL_off (sv); |
80 | SvRMAGICAL_off (sv); |
76 | |
81 | |
77 | if (SvTYPE (sv) >= SVt_PVMG) |
82 | if (SvTYPE (sv) >= SVt_PVMG) |
78 | { |
83 | { |
79 | MAGIC *mg = SvMAGIC (sv); |
84 | |
80 | while (mg) |
85 | if (SvTYPE (sv) != SVt_PVMG || SvPAD_OUR (sv)) |
81 | { |
86 | { |
82 | if (mg->mg_obj == targ) |
87 | MAGIC *mg = SvMAGIC (sv); |
83 | res_pair (form ("referenced (in mg_obj) by '%c' type magic attached to", mg->mg_type)); |
|
|
84 | |
88 | |
85 | if ((SV *)mg->mg_ptr == targ && mg->mg_flags & MGf_REFCOUNTED) |
89 | while (mg) |
|
|
90 | { |
|
|
91 | if (mg->mg_obj == targ) |
86 | res_pair (form ("referenced (in mg_ptr) by '%c' type magic attached to", mg->mg_type)); |
92 | res_pair (form ("referenced (in mg_obj) by '%c' type magic attached to", mg->mg_type)); |
87 | |
93 | |
|
|
94 | if ((SV *)mg->mg_ptr == targ && mg->mg_flags & MGf_REFCOUNTED) |
|
|
95 | res_pair (form ("referenced (in mg_ptr) by '%c' type magic attached to", mg->mg_type)); |
|
|
96 | |
88 | mg = mg->mg_moremagic; |
97 | mg = mg->mg_moremagic; |
|
|
98 | } |
89 | } |
99 | } |
90 | } |
100 | } |
91 | |
101 | |
92 | if (SvROK (sv)) |
102 | if (SvROK (sv)) |
93 | { |
103 | { |
… | |
… | |
119 | |
129 | |
120 | case SVt_PVCV: |
130 | case SVt_PVCV: |
121 | { |
131 | { |
122 | int depth = CvDEPTH (sv); |
132 | int depth = CvDEPTH (sv); |
123 | |
133 | |
|
|
134 | /* Anonymous subs have a padlist but zero depth */ |
124 | if (!depth && CvPADLIST(sv)) |
135 | if (!depth && CvPADLIST (sv)) |
125 | depth = 1; |
136 | depth = 1; |
126 | |
137 | |
127 | if (depth) |
138 | if (depth) |
128 | { |
139 | { |
129 | AV *padlist = CvPADLIST (sv); |
140 | AV *padlist = CvPADLIST (sv); |
… | |
… | |
134 | |
145 | |
135 | av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ |
146 | av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ |
136 | |
147 | |
137 | for (i = AvFILLp (pad) + 1; i--; ) |
148 | for (i = AvFILLp (pad) + 1; i--; ) |
138 | if (AvARRAY (pad)[i] == targ) |
149 | if (AvARRAY (pad)[i] == targ) |
|
|
150 | { |
|
|
151 | /* Values from constant functions are stored in the pad without any name */ |
|
|
152 | SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; |
|
|
153 | |
|
|
154 | if (name_sv && SvPOK (name_sv)) |
139 | res_pair (form ("in the lexical '%s' in", SvPVX (AvARRAY (AvARRAY (padlist)[0])[i]))); |
155 | res_pair (form ("in the lexical '%s' in", SvPVX (name_sv))); |
|
|
156 | else |
|
|
157 | res_pair ("in an unnamed lexical in"); |
|
|
158 | } |
140 | |
159 | |
141 | --depth; |
160 | --depth; |
142 | } |
161 | } |
143 | } |
162 | } |
144 | |
163 | |
|
|
164 | if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ) |
|
|
165 | res_pair ("the constant value of"); |
|
|
166 | |
145 | if ((SV*)CvOUTSIDE(sv) == targ) |
167 | if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ) |
146 | res_pair ("the containing scope for"); |
168 | res_pair ("the containing scope for"); |
147 | } |
169 | } |
148 | |
170 | |
149 | break; |
171 | break; |
150 | |
172 | |