… | |
… | |
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)); \ |
|
|
23 | if (rmagical) SvRMAGICAL_on (sv); \ |
19 | av_push (av, sv_rvweaken (newRV_inc (sv))); \ |
24 | av_push (av, sv_rvweaken (newRV_inc (sv))); \ |
|
|
25 | if (rmagical) SvRMAGICAL_off (sv); \ |
20 | av_push (about, newRV_noinc ((SV *)av)); \ |
26 | av_push (about, newRV_noinc ((SV *)av)); \ |
21 | } |
27 | } while (0) |
22 | |
28 | |
23 | #define res_gv(sigil) \ |
29 | #define res_gv(sigil) \ |
24 | { \ |
30 | do { \ |
25 | AV *av = newAV (); \ |
31 | AV *av = newAV (); \ |
26 | 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, \ |
27 | HvNAME (GvSTASH (sv)), \ |
33 | HvNAME (GvSTASH (sv)), \ |
28 | GvNAMELEN (sv), GvNAME (sv) ? GvNAME (sv) : "<anonymous>"), \ |
34 | GvNAMELEN (sv), GvNAME (sv) ? GvNAME (sv) : "<anonymous>"), \ |
29 | 0)); \ |
35 | 0)); \ |
30 | av_push (about, newRV_noinc ((SV *)av)); \ |
36 | av_push (about, newRV_noinc ((SV *)av)); \ |
31 | } |
37 | } while (0) |
32 | |
38 | |
33 | MODULE = Devel::FindRef PACKAGE = Devel::FindRef |
39 | MODULE = Devel::FindRef PACKAGE = Devel::FindRef |
34 | |
40 | |
35 | PROTOTYPES: ENABLE |
41 | PROTOTYPES: ENABLE |
36 | |
42 | |
… | |
… | |
44 | void |
50 | void |
45 | find_ (SV *target) |
51 | find_ (SV *target) |
46 | PPCODE: |
52 | PPCODE: |
47 | { |
53 | { |
48 | SV *arena, *targ; |
54 | SV *arena, *targ; |
49 | int rmagical, i; |
55 | U32 rmagical; |
|
|
56 | int i; |
50 | AV *about = newAV (); |
57 | AV *about = newAV (); |
51 | AV *excl = newAV (); |
58 | AV *excl = newAV (); |
52 | |
59 | |
53 | if (!SvROK (target)) |
60 | if (!SvROK (target)) |
54 | croak ("find expects a reference to a perl value"); |
61 | croak ("find expects a reference to a perl value"); |
… | |
… | |
72 | if ((rmagical = SvRMAGICAL (sv))) |
79 | if ((rmagical = SvRMAGICAL (sv))) |
73 | SvRMAGICAL_off (sv); |
80 | SvRMAGICAL_off (sv); |
74 | |
81 | |
75 | if (SvTYPE (sv) >= SVt_PVMG) |
82 | if (SvTYPE (sv) >= SVt_PVMG) |
76 | { |
83 | { |
77 | MAGIC *mg = SvMAGIC (sv); |
84 | |
78 | while (mg) |
85 | if (SvTYPE (sv) != SVt_PVMG || SvPAD_OUR (sv)) |
79 | { |
86 | { |
80 | if (mg->mg_obj == targ) |
87 | MAGIC *mg = SvMAGIC (sv); |
81 | res_pair (form ("referenced (in mg_obj) by '%c' type magic attached to", mg->mg_type)); |
|
|
82 | |
88 | |
83 | if ((SV *)mg->mg_ptr == targ && mg->mg_flags & MGf_REFCOUNTED) |
89 | while (mg) |
|
|
90 | { |
|
|
91 | if (mg->mg_obj == targ) |
84 | 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)); |
85 | |
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 | |
86 | mg = mg->mg_moremagic; |
97 | mg = mg->mg_moremagic; |
|
|
98 | } |
87 | } |
99 | } |
88 | } |
100 | } |
89 | |
101 | |
90 | if (SvROK (sv)) |
102 | if (SvROK (sv)) |
91 | { |
103 | { |
… | |
… | |
117 | |
129 | |
118 | case SVt_PVCV: |
130 | case SVt_PVCV: |
119 | { |
131 | { |
120 | int depth = CvDEPTH (sv); |
132 | int depth = CvDEPTH (sv); |
121 | |
133 | |
|
|
134 | /* Anonymous subs have a padlist but zero depth */ |
|
|
135 | if (!depth && CvPADLIST (sv)) |
|
|
136 | depth = 1; |
|
|
137 | |
122 | if (depth) |
138 | if (depth) |
123 | { |
139 | { |
124 | AV *padlist = CvPADLIST (sv); |
140 | AV *padlist = CvPADLIST (sv); |
125 | |
141 | |
126 | while (depth) |
142 | while (depth) |
127 | { |
143 | { |
128 | AV *pad = (AV *)AvARRAY (padlist)[depth]; |
144 | AV *pad = (AV *)AvARRAY (padlist)[depth]; |
129 | |
145 | |
130 | 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 */ |
131 | |
147 | |
132 | for (i = AvFILLp (pad); i--; ) |
148 | for (i = AvFILLp (pad) + 1; i--; ) |
133 | 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)) |
134 | 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 | } |
135 | |
159 | |
136 | --depth; |
160 | --depth; |
137 | } |
161 | } |
138 | } |
162 | } |
|
|
163 | |
|
|
164 | if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ) |
|
|
165 | res_pair ("the constant value of"); |
|
|
166 | |
|
|
167 | if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ) |
|
|
168 | res_pair ("the containing scope for"); |
139 | } |
169 | } |
140 | |
170 | |
141 | break; |
171 | break; |
142 | |
172 | |
143 | case SVt_PVGV: |
173 | case SVt_PVGV: |