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.14 by root, Sat Jul 19 01:17:12 2008 UTC vs.
Revision 1.18 by root, Mon Dec 1 13:22:43 2008 UTC

1package Devel::FindRef; 1package Devel::FindRef;
2 2
3no warnings; # I hate warning nazis
3use strict; 4use strict;
4 5
5use XSLoader; 6use XSLoader;
6use Scalar::Util; 7use Scalar::Util;
7 8
8BEGIN { 9BEGIN {
9 our $VERSION = '1.3'; 10 our $VERSION = '1.31';
10 XSLoader::load __PACKAGE__, $VERSION; 11 XSLoader::load __PACKAGE__, $VERSION;
11} 12}
12 13
13=head1 NAME 14=head1 NAME
14 15
15Devel::FindRef - where is that reference to my variable hiding? 16Devel::FindRef - where is that reference to my variable hiding?
16 17
17=head1 SYNOPSIS 18=head1 SYNOPSIS
18 19
19 use Devel::FindRef; 20 use Devel::FindRef;
21
22 print Devel::FindRef::track \$some_variable;
20 23
21=head1 DESCRIPTION 24=head1 DESCRIPTION
22 25
23Tracking down reference problems (e.g. you expect some object to be 26Tracking down reference problems (e.g. you expect some object to be
24destroyed, 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
101 104
102=cut 105=cut
103 106
104sub find($); 107sub find($);
105 108
109sub _f($) {
110 "$_[0] [refcount " . (_refcnt $_[0]) . "]"
111}
112
106sub track { 113sub track {
107 my ($ref, $depth) = @_; 114 my ($ref, $depth) = @_;
108 @_ = (); 115 @_ = ();
109 116
110 my $buf = ""; 117 my $buf = "";
120 if (@about) { 127 if (@about) {
121 for my $about (@about) { 128 for my $about (@about) {
122 $buf .= "$indent" . (@about > 1 ? "+- " : " ") . $about->[0]; 129 $buf .= "$indent" . (@about > 1 ? "+- " : " ") . $about->[0];
123 if (@$about > 1) { 130 if (@$about > 1) {
124 if ($seen{ref2ptr $about->[1]}++) { 131 if ($seen{ref2ptr $about->[1]}++) {
125 $buf .= " $about->[1], which was seen before.\n"; 132 $buf .= " " . (_f $about->[1]) . ", which was seen before.\n";
126 } else { 133 } else {
127 $buf .= " $about->[1], which is\n"; 134 $buf .= " " . (_f $about->[1]) . ", which is\n";
128 $track->(\$about->[1], $depth - 1, $about == $about[-1] ? "$indent " : "$indent| "); 135 $track->(\$about->[1], $depth - 1, $about == $about[-1] ? "$indent " : "$indent| ");
129 } 136 }
130 } else { 137 } else {
131 $buf .= ".\n"; 138 $buf .= ".\n";
132 } 139 }
137 } else { 144 } else {
138 $buf .= "$indent not referenced within the search depth.\n"; 145 $buf .= "$indent not referenced within the search depth.\n";
139 } 146 }
140 }; 147 };
141 148
142 $buf .= "$ref is\n"; 149 $buf .= (_f $ref) . " is\n";
143 $track->(\$ref, $depth || $ENV{PERL_DEVEL_FINDREF_DEPTH} || 10, ""); 150 $track->(\$ref, $depth || $ENV{PERL_DEVEL_FINDREF_DEPTH} || 10, "");
144 $buf 151 $buf
145} 152}
146 153
147=item @references = Devel::FindRef::find $ref 154=item @references = Devel::FindRef::find $ref
188 195
189=head1 AUTHOR 196=head1 AUTHOR
190 197
191Marc Lehmann <pcg@goof.com>. 198Marc Lehmann <pcg@goof.com>.
192 199
193=head1 BUGS
194
195Only code values, arrays, hashes, scalars and magic are being looked at.
196
197This is a quick hack only.
198
199=head1 COPYRIGHT AND LICENSE 200=head1 COPYRIGHT AND LICENSE
200 201
201Copyright (C) 2007 by Marc Lehmann. 202Copyright (C) 2007, 2008 by Marc Lehmann.
202 203
203This library is free software; you can redistribute it and/or modify 204This library is free software; you can redistribute it and/or modify
204it 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,
205at 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.
206 207

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines