ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Devel-FindRef/FindRef.pm
(Generate patch)

Comparing Devel-FindRef/FindRef.pm (file contents):
Revision 1.15 by root, Sat Jul 19 01:38:57 2008 UTC vs.
Revision 1.18 by root, Mon Dec 1 13:22:43 2008 UTC

16Devel::FindRef - where is that reference to my variable hiding? 16Devel::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
24Tracking down reference problems (e.g. you expect some object to be 26Tracking down reference problems (e.g. you expect some object to be
25destroyed, but there are still references to it that keep it alive) can be 27destroyed, but there are still references to it that keep it alive) can be
102 104
103=cut 105=cut
104 106
105sub find($); 107sub find($);
106 108
109sub _f($) {
110 "$_[0] [refcount " . (_refcnt $_[0]) . "]"
111}
112
107sub track { 113sub 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
192Marc Lehmann <pcg@goof.com>. 198Marc Lehmann <pcg@goof.com>.
193 199
194=head1 BUGS
195
196Only code values, arrays, hashes, scalars and magic are being looked at.
197
198This is a quick hack only.
199
200=head1 COPYRIGHT AND LICENSE 200=head1 COPYRIGHT AND LICENSE
201 201
202Copyright (C) 2007 by Marc Lehmann. 202Copyright (C) 2007, 2008 by Marc Lehmann.
203 203
204This library is free software; you can redistribute it and/or modify 204This library is free software; you can redistribute it and/or modify
205it under the same terms as Perl itself, either Perl version 5.8.8 or, 205it under the same terms as Perl itself, either Perl version 5.8.8 or,
206at your option, any later version of Perl 5 you may have available. 206at your option, any later version of Perl 5 you may have available.
207 207

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines