… | |
… | |
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 | { |
|
|
87 | /* I have no clue what this is */ |
|
|
88 | /* maybe some placeholder for our variables for eval? */ |
|
|
89 | /* it doesn'T seem to reference anything, so we should be able to ignore it */ |
|
|
90 | } |
|
|
91 | else |
|
|
92 | { |
|
|
93 | MAGIC *mg = SvMAGIC (sv); |
|
|
94 | |
|
|
95 | while (mg) |
|
|
96 | { |
82 | if (mg->mg_obj == targ) |
97 | if (mg->mg_obj == targ) |
83 | res_pair (form ("referenced (in mg_obj) by '%c' type magic attached to", mg->mg_type)); |
98 | res_pair (form ("referenced (in mg_obj) by '%c' type magic attached to", mg->mg_type)); |
84 | |
99 | |
85 | if ((SV *)mg->mg_ptr == targ && mg->mg_flags & MGf_REFCOUNTED) |
100 | if ((SV *)mg->mg_ptr == targ && mg->mg_flags & MGf_REFCOUNTED) |
86 | res_pair (form ("referenced (in mg_ptr) by '%c' type magic attached to", mg->mg_type)); |
101 | res_pair (form ("referenced (in mg_ptr) by '%c' type magic attached to", mg->mg_type)); |
87 | |
102 | |
88 | mg = mg->mg_moremagic; |
103 | mg = mg->mg_moremagic; |
|
|
104 | } |
89 | } |
105 | } |
90 | } |
106 | } |
91 | |
107 | |
92 | if (SvROK (sv)) |
108 | if (SvROK (sv)) |
93 | { |
109 | { |
… | |
… | |
119 | |
135 | |
120 | case SVt_PVCV: |
136 | case SVt_PVCV: |
121 | { |
137 | { |
122 | int depth = CvDEPTH (sv); |
138 | int depth = CvDEPTH (sv); |
123 | |
139 | |
|
|
140 | /* Anonymous subs have a padlist but zero depth */ |
124 | if (!depth && CvPADLIST(sv)) |
141 | if (!depth && CvPADLIST (sv)) |
125 | depth = 1; |
142 | depth = 1; |
126 | |
143 | |
127 | if (depth) |
144 | if (depth) |
128 | { |
145 | { |
129 | AV *padlist = CvPADLIST (sv); |
146 | AV *padlist = CvPADLIST (sv); |
… | |
… | |
134 | |
151 | |
135 | av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ |
152 | av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ |
136 | |
153 | |
137 | for (i = AvFILLp (pad) + 1; i--; ) |
154 | for (i = AvFILLp (pad) + 1; i--; ) |
138 | if (AvARRAY (pad)[i] == targ) |
155 | if (AvARRAY (pad)[i] == targ) |
|
|
156 | { |
|
|
157 | /* Values from constant functions are stored in the pad without any name */ |
|
|
158 | SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; |
|
|
159 | |
|
|
160 | if (name_sv && SvPOK (name_sv)) |
139 | res_pair (form ("in the lexical '%s' in", SvPVX (AvARRAY (AvARRAY (padlist)[0])[i]))); |
161 | res_pair (form ("in the lexical '%s' in", SvPVX (name_sv))); |
|
|
162 | else |
|
|
163 | res_pair ("in an unnamed lexical in"); |
|
|
164 | } |
140 | |
165 | |
141 | --depth; |
166 | --depth; |
142 | } |
167 | } |
143 | } |
168 | } |
144 | |
169 | |
|
|
170 | if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ) |
|
|
171 | res_pair ("the constant value of"); |
|
|
172 | |
145 | if ((SV*)CvOUTSIDE(sv) == targ) |
173 | if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ) |
146 | res_pair ("the containing scope for"); |
174 | res_pair ("the containing scope for"); |
147 | } |
175 | } |
148 | |
176 | |
149 | break; |
177 | break; |
150 | |
178 | |