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