1 | package Devel::FindRef; |
1 | package Devel::FindRef; |
2 | |
2 | |
3 | no warnings; # I hate warning nazis |
3 | use common::sense; |
4 | use strict; |
|
|
5 | |
4 | |
6 | use XSLoader; |
5 | use XSLoader; |
7 | use Scalar::Util; |
6 | use Scalar::Util; |
8 | |
7 | |
9 | BEGIN { |
8 | BEGIN { |
10 | our $VERSION = '1.4'; |
9 | our $VERSION = '1.422'; |
11 | XSLoader::load __PACKAGE__, $VERSION; |
10 | XSLoader::load __PACKAGE__, $VERSION; |
12 | } |
11 | } |
13 | |
12 | |
14 | =head1 NAME |
13 | =head1 NAME |
15 | |
14 | |
… | |
… | |
88 | It is a bit convoluted to read, but basically it says that the value |
87 | It is a bit convoluted to read, but basically it says that the value |
89 | stored in C<$var> is referenced by: |
88 | stored in C<$var> is referenced by: |
90 | |
89 | |
91 | =over 4 |
90 | =over 4 |
92 | |
91 | |
93 | =item - in the lexical C<$closure_var> (0x8abcc8), which is inside an instantiated |
92 | =item - the lexical C<$closure_var> (0x8abcc8), which is inside an instantiated |
94 | closure, which in turn is used quite a bit. |
93 | closure, which in turn is used quite a bit. |
95 | |
94 | |
96 | =item - in the package-level lexical C<$global_my>. |
95 | =item - the package-level lexical C<$global_my>. |
97 | |
96 | |
98 | =item - in the global package variable named C<$Test::var>. |
97 | =item - the global package variable named C<$Test::var>. |
99 | |
98 | |
100 | =item - in the hash element C<ukukey2>, in the hash in the my variable |
99 | =item - the hash element C<ukukey2>, in the hash in the my variable |
101 | C<$testsub_local> in the sub C<Test::testsub> and also in the hash |
100 | C<$testsub_local> in the sub C<Test::testsub> and also in the hash |
102 | C<$referenced by Test::hash2>. |
101 | C<$referenced by Test::hash2>. |
103 | |
102 | |
104 | =item - in the hash element with key C<ukukey> in the hash stored in |
103 | =item - the hash element with key C<ukukey> in the hash stored in |
105 | C<%Test::hash>. |
104 | C<%Test::hash>. |
106 | |
105 | |
107 | =item - some anonymous mortalised reference on the stack (which is caused |
106 | =item - some anonymous mortalised reference on the stack (which is caused |
108 | by calling C<track> with the expression C<\$var>, which creates the |
107 | by calling C<track> with the expression C<\$var>, which creates the |
109 | reference). |
108 | reference). |
… | |
… | |
151 | |
150 | |
152 | if ($depth) { |
151 | if ($depth) { |
153 | my (@about) = find $$refref; |
152 | my (@about) = find $$refref; |
154 | if (@about) { |
153 | if (@about) { |
155 | for my $about (@about) { |
154 | for my $about (@about) { |
|
|
155 | $about->[0] =~ s/([^\x20-\x7e])/sprintf "\\{%02x}", ord $1/ge; |
156 | $buf .= "$indent" . (@about > 1 ? "+- " : "") . $about->[0]; |
156 | $buf .= "$indent" . (@about > 1 ? "+- " : "") . $about->[0]; |
157 | if (@$about > 1) { |
157 | if (@$about > 1) { |
158 | if ($seen{ref2ptr $about->[1]}++) { |
158 | if ($seen{ref2ptr $about->[1]}++) { |
159 | $buf .= " " . (_f $about->[1]) . ", which was seen before.\n"; |
159 | $buf .= " " . (_f $about->[1]) . ", which was seen before.\n"; |
160 | } else { |
160 | } else { |
… | |
… | |
172 | $buf .= "$indent not referenced within the search depth.\n"; |
172 | $buf .= "$indent not referenced within the search depth.\n"; |
173 | } |
173 | } |
174 | }; |
174 | }; |
175 | |
175 | |
176 | $buf .= (_f $ref) . " is\n"; |
176 | $buf .= (_f $ref) . " is\n"; |
|
|
177 | |
177 | $track->(\$ref, $depth || $ENV{PERL_DEVEL_FINDREF_DEPTH} || 10, ""); |
178 | $track->(\$ref, $depth || $ENV{PERL_DEVEL_FINDREF_DEPTH} || 10, ""); |
178 | $buf |
179 | $buf |
179 | } |
180 | } |
180 | |
181 | |
181 | =item @references = Devel::FindRef::find $ref |
182 | =item @references = Devel::FindRef::find $ref |
… | |
… | |
191 | =cut |
192 | =cut |
192 | |
193 | |
193 | sub find($) { |
194 | sub find($) { |
194 | my ($about, $excl) = &find_; |
195 | my ($about, $excl) = &find_; |
195 | my %excl = map +($_ => undef), @$excl; |
196 | my %excl = map +($_ => undef), @$excl; |
196 | grep !exists $excl{ref2ptr $_->[1]}, @$about |
197 | grep !($#$_ && exists $excl{ref2ptr $_->[1]}), @$about |
197 | } |
198 | } |
198 | |
199 | |
199 | =item $ref = Devel::FindRef::ptr2ref $integer |
200 | =item $ref = Devel::FindRef::ptr2ref $integer |
200 | |
201 | |
201 | Sometimes you know (from debugging output) the address of a perl scalar |
202 | Sometimes you know (from debugging output) the address of a perl scalar |