… | |
… | |
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 | #define res_pair(text) \ |
15 | #define res_pair(text) \ |
16 | { \ |
16 | { \ |
17 | AV *av = newAV (); \ |
17 | AV *av = newAV (); \ |
18 | av_push (av, newSVpv (text, 0)); \ |
18 | av_push (av, newSVpv (text, 0)); \ |
|
|
19 | if (rmagical) SvRMAGICAL_on (sv); \ |
19 | av_push (av, newRV_inc (sv)); \ |
20 | av_push (av, sv_rvweaken (newRV_inc (sv))); \ |
|
|
21 | if (rmagical) SvRMAGICAL_off (sv); \ |
20 | av_push (about, newRV_noinc ((SV *)av)); \ |
22 | av_push (about, newRV_noinc ((SV *)av)); \ |
21 | } |
23 | } |
22 | |
24 | |
23 | #define res_gv(sigil) \ |
25 | #define res_gv(sigil) \ |
24 | { \ |
26 | { \ |
25 | AV *av = newAV (); \ |
27 | AV *av = newAV (); \ |
26 | av_push (av, newSVpv (form ("in the global %c%s::%.*s", sigil, \ |
28 | av_push (av, newSVpv (form ("in the global %c%s::%.*s", sigil, \ |
27 | HvNAME (GvSTASH (sv)), \ |
29 | HvNAME (GvSTASH (sv)), \ |
28 | GvNAMELEN (sv), GvNAME (sv) ? GvNAME (sv) : "<anonymous>"), \ |
30 | GvNAMELEN (sv), GvNAME (sv) ? GvNAME (sv) : "<anonymous>"), \ |
29 | 0)); \ |
31 | 0)); \ |
30 | av_push (about, newRV_noinc ((SV *)av)); \ |
32 | av_push (about, newRV_noinc ((SV *)av)); \ |
31 | } |
33 | } |
32 | |
34 | |
33 | MODULE = Devel::FindRef PACKAGE = Devel::FindRef |
35 | MODULE = Devel::FindRef PACKAGE = Devel::FindRef |
34 | |
36 | |
35 | PROTOTYPES: ENABLE |
37 | PROTOTYPES: ENABLE |
… | |
… | |
77 | MAGIC *mg = SvMAGIC (sv); |
79 | MAGIC *mg = SvMAGIC (sv); |
78 | while (mg) |
80 | while (mg) |
79 | { |
81 | { |
80 | if (mg->mg_obj == targ) |
82 | if (mg->mg_obj == targ) |
81 | res_pair (form ("referenced (in mg_obj) by '%c' type magic attached to", mg->mg_type)); |
83 | res_pair (form ("referenced (in mg_obj) by '%c' type magic attached to", mg->mg_type)); |
|
|
84 | |
82 | if ((SV *)mg->mg_ptr == targ && mg->mg_flags & MGf_REFCOUNTED) |
85 | if ((SV *)mg->mg_ptr == targ && mg->mg_flags & MGf_REFCOUNTED) |
83 | res_pair (form ("referenced (in mg_ptr) by '%c' type magic attached to", mg->mg_type)); |
86 | res_pair (form ("referenced (in mg_ptr) by '%c' type magic attached to", mg->mg_type)); |
84 | |
87 | |
85 | mg = mg->mg_moremagic; |
88 | mg = mg->mg_moremagic; |
86 | } |
89 | } |
87 | } |
90 | } |
88 | |
91 | |
89 | switch (SvTYPE (sv)) |
92 | if (SvROK (sv)) |
90 | { |
93 | { |
91 | case SVt_RV: |
|
|
92 | if (sv != target && SvRV (sv) == targ) |
94 | if (sv != target && SvRV (sv) == targ && !SvWEAKREF (sv)) |
93 | res_pair ("referenced by"); |
95 | res_pair ("referenced by"); |
|
|
96 | } |
|
|
97 | else |
|
|
98 | switch (SvTYPE (sv)) |
94 | break; |
99 | { |
|
|
100 | case SVt_PVAV: |
|
|
101 | if (AvREAL (sv)) |
|
|
102 | for (i = AvFILLp (sv) + 1; i--; ) |
|
|
103 | if (AvARRAY (sv)[i] == targ) |
|
|
104 | res_pair (form ("in array element %d of", i)); |
95 | |
105 | |
96 | case SVt_PVAV: |
|
|
97 | if (AvREAL (sv)) |
|
|
98 | for (i = AvFILLp (sv) + 1; i--; ) |
|
|
99 | if (AvARRAY (sv)[i] == targ) |
|
|
100 | res_pair (form ("in array element %d of", i)); |
|
|
101 | break; |
106 | break; |
102 | |
107 | |
103 | case SVt_PVHV: |
108 | case SVt_PVHV: |
104 | if (hv_iterinit ((HV *)sv)) |
109 | if (hv_iterinit ((HV *)sv)) |
|
|
110 | { |
|
|
111 | HE *he; |
|
|
112 | |
|
|
113 | while ((he = hv_iternext ((HV *)sv))) |
|
|
114 | if (HeVAL (he) == targ) |
|
|
115 | res_pair (form ("in the member '%.*s' of", HeKLEN (he), HeKEY (he))); |
|
|
116 | } |
|
|
117 | |
|
|
118 | break; |
|
|
119 | |
|
|
120 | case SVt_PVCV: |
105 | { |
121 | { |
|
|
122 | int depth = CvDEPTH (sv); |
|
|
123 | |
|
|
124 | if (!depth && CvPADLIST(sv)) |
|
|
125 | depth = 1; |
|
|
126 | |
|
|
127 | if (depth) |
106 | HE *he; |
128 | { |
107 | while ((he = hv_iternext ((HV *)sv))) |
129 | AV *padlist = CvPADLIST (sv); |
|
|
130 | |
|
|
131 | while (depth) |
|
|
132 | { |
|
|
133 | AV *pad = (AV *)AvARRAY (padlist)[depth]; |
|
|
134 | |
|
|
135 | av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ |
|
|
136 | |
|
|
137 | for (i = AvFILLp (pad) + 1; i--; ) |
|
|
138 | if (AvARRAY (pad)[i] == targ) |
|
|
139 | res_pair (form ("in the lexical '%s' in", SvPVX (AvARRAY (AvARRAY (padlist)[0])[i]))); |
|
|
140 | |
|
|
141 | --depth; |
|
|
142 | } |
|
|
143 | } |
|
|
144 | |
108 | if (HeVAL (he) == targ) |
145 | if ((SV*)CvOUTSIDE(sv) == targ) |
109 | res_pair (form ("in the member '%.*s' of", HeKLEN (he), HeKEY (he))); |
146 | res_pair ("the containing scope for"); |
110 | } |
147 | } |
111 | break; |
|
|
112 | |
148 | |
|
|
149 | break; |
|
|
150 | |
113 | case SVt_PVCV: |
151 | case SVt_PVGV: |
114 | { |
|
|
115 | int depth = CvDEPTH (sv); |
|
|
116 | if (depth) |
152 | if (GvGP (sv)) |
117 | { |
153 | { |
118 | AV *padlist = CvPADLIST (sv); |
154 | if (GvSV (sv) == (SV *)targ) res_gv ('$'); |
119 | while (depth) |
155 | if (GvAV (sv) == (AV *)targ) res_gv ('@'); |
|
|
156 | if (GvHV (sv) == (HV *)targ) res_gv ('%'); |
|
|
157 | if (GvCV (sv) == (CV *)targ) res_gv ('&'); |
120 | { |
158 | } |
121 | AV *pad = (AV *)AvARRAY (padlist)[depth]; |
|
|
122 | av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads from being found */ |
|
|
123 | for (i = AvFILLp (pad); i--; ) |
|
|
124 | if (AvARRAY (pad)[i] == targ) |
|
|
125 | res_pair (form ("in the lexical '%s' in", SvPVX (AvARRAY (AvARRAY (padlist)[0])[i]))); |
|
|
126 | |
159 | |
127 | --depth; |
|
|
128 | } |
|
|
129 | } |
|
|
130 | } |
|
|
131 | break; |
160 | break; |
132 | |
|
|
133 | case SVt_PVGV: |
|
|
134 | if (GvGP (sv)) |
|
|
135 | { |
|
|
136 | if (GvSV (sv) == targ) |
|
|
137 | res_gv ('$'); |
|
|
138 | if (GvAV (sv) == (AV *)targ) |
|
|
139 | res_gv ('@'); |
|
|
140 | if (GvHV (sv) == (HV *)targ) |
|
|
141 | res_gv ('%'); |
|
|
142 | if (GvCV (sv) == (CV *)targ) |
|
|
143 | res_gv ('&'); |
|
|
144 | } |
|
|
145 | break; |
|
|
146 | } |
161 | } |
147 | |
162 | |
148 | if (rmagical) |
163 | if (rmagical) |
149 | SvRMAGICAL_off (sv); |
164 | SvRMAGICAL_on (sv); |
150 | } |
165 | } |
151 | } |
166 | } |
152 | |
167 | |
153 | EXTEND (SP, 2); |
168 | EXTEND (SP, 2); |
154 | PUSHs (sv_2mortal (newRV_noinc ((SV *)about))); |
169 | PUSHs (sv_2mortal (newRV_noinc ((SV *)about))); |