… | |
… | |
16 | Devel::FindRef - where is that reference to my variable hiding? |
16 | Devel::FindRef - where is that reference to my variable hiding? |
17 | |
17 | |
18 | =head1 SYNOPSIS |
18 | =head1 SYNOPSIS |
19 | |
19 | |
20 | use Devel::FindRef; |
20 | use Devel::FindRef; |
|
|
21 | |
|
|
22 | print Devel::FindRef::track \$some_variable; |
21 | |
23 | |
22 | =head1 DESCRIPTION |
24 | =head1 DESCRIPTION |
23 | |
25 | |
24 | Tracking down reference problems (e.g. you expect some object to be |
26 | Tracking down reference problems (e.g. you expect some object to be |
25 | destroyed, but there are still references to it that keep it alive) can be |
27 | destroyed, but there are still references to it that keep it alive) can be |
… | |
… | |
102 | |
104 | |
103 | =cut |
105 | =cut |
104 | |
106 | |
105 | sub find($); |
107 | sub find($); |
106 | |
108 | |
|
|
109 | sub _f($) { |
|
|
110 | "$_[0] [refcount " . (_refcnt $_[0]) . "]" |
|
|
111 | } |
|
|
112 | |
107 | sub track { |
113 | sub track { |
108 | my ($ref, $depth) = @_; |
114 | my ($ref, $depth) = @_; |
109 | @_ = (); |
115 | @_ = (); |
110 | |
116 | |
111 | my $buf = ""; |
117 | my $buf = ""; |
… | |
… | |
121 | if (@about) { |
127 | if (@about) { |
122 | for my $about (@about) { |
128 | for my $about (@about) { |
123 | $buf .= "$indent" . (@about > 1 ? "+- " : " ") . $about->[0]; |
129 | $buf .= "$indent" . (@about > 1 ? "+- " : " ") . $about->[0]; |
124 | if (@$about > 1) { |
130 | if (@$about > 1) { |
125 | if ($seen{ref2ptr $about->[1]}++) { |
131 | if ($seen{ref2ptr $about->[1]}++) { |
126 | $buf .= " $about->[1], which was seen before.\n"; |
132 | $buf .= " " . (_f $about->[1]) . ", which was seen before.\n"; |
127 | } else { |
133 | } else { |
128 | $buf .= " $about->[1], which is\n"; |
134 | $buf .= " " . (_f $about->[1]) . ", which is\n"; |
129 | $track->(\$about->[1], $depth - 1, $about == $about[-1] ? "$indent " : "$indent| "); |
135 | $track->(\$about->[1], $depth - 1, $about == $about[-1] ? "$indent " : "$indent| "); |
130 | } |
136 | } |
131 | } else { |
137 | } else { |
132 | $buf .= ".\n"; |
138 | $buf .= ".\n"; |
133 | } |
139 | } |
… | |
… | |
138 | } else { |
144 | } else { |
139 | $buf .= "$indent not referenced within the search depth.\n"; |
145 | $buf .= "$indent not referenced within the search depth.\n"; |
140 | } |
146 | } |
141 | }; |
147 | }; |
142 | |
148 | |
143 | $buf .= "$ref is\n"; |
149 | $buf .= (_f $ref) . " is\n"; |
144 | $track->(\$ref, $depth || $ENV{PERL_DEVEL_FINDREF_DEPTH} || 10, ""); |
150 | $track->(\$ref, $depth || $ENV{PERL_DEVEL_FINDREF_DEPTH} || 10, ""); |
145 | $buf |
151 | $buf |
146 | } |
152 | } |
147 | |
153 | |
148 | =item @references = Devel::FindRef::find $ref |
154 | =item @references = Devel::FindRef::find $ref |
… | |
… | |
189 | |
195 | |
190 | =head1 AUTHOR |
196 | =head1 AUTHOR |
191 | |
197 | |
192 | Marc Lehmann <pcg@goof.com>. |
198 | Marc Lehmann <pcg@goof.com>. |
193 | |
199 | |
194 | =head1 BUGS |
|
|
195 | |
|
|
196 | Only code values, arrays, hashes, scalars and magic are being looked at. |
|
|
197 | |
|
|
198 | This is a quick hack only. |
|
|
199 | |
|
|
200 | =head1 COPYRIGHT AND LICENSE |
200 | =head1 COPYRIGHT AND LICENSE |
201 | |
201 | |
202 | Copyright (C) 2007 by Marc Lehmann. |
202 | Copyright (C) 2007, 2008 by Marc Lehmann. |
203 | |
203 | |
204 | This library is free software; you can redistribute it and/or modify |
204 | This library is free software; you can redistribute it and/or modify |
205 | it under the same terms as Perl itself, either Perl version 5.8.8 or, |
205 | it under the same terms as Perl itself, either Perl version 5.8.8 or, |
206 | at your option, any later version of Perl 5 you may have available. |
206 | at your option, any later version of Perl 5 you may have available. |
207 | |
207 | |