… | |
… | |
107 | sub track { |
107 | sub track { |
108 | my ($ref, $depth) = @_; |
108 | my ($ref, $depth) = @_; |
109 | @_ = (); |
109 | @_ = (); |
110 | |
110 | |
111 | my $buf = ""; |
111 | my $buf = ""; |
|
|
112 | my %seen; |
112 | |
113 | |
113 | Scalar::Util::weaken $ref; |
114 | Scalar::Util::weaken $ref; |
114 | |
115 | |
115 | my $track; $track = sub { |
116 | my $track; $track = sub { |
116 | my ($refref, $depth, $indent) = @_; |
117 | my ($refref, $depth, $indent) = @_; |
117 | |
118 | |
118 | if ($depth) { |
119 | if ($depth) { |
119 | my (@about) = find $$refref; |
120 | my (@about) = find $$refref; |
120 | if (@about) { |
121 | if (@about) { |
121 | for my $about (@about) { |
122 | for my $about (@about) { |
122 | $buf .= (" ") x $indent; |
123 | $buf .= "$indent" . (@about > 1 ? "+- " : " ") . $about->[0]; |
123 | $buf .= $about->[0]; |
|
|
124 | if (@$about > 1) { |
124 | if (@$about > 1) { |
|
|
125 | if ($seen{$about->[1]+0}++) { |
|
|
126 | $buf .= " $about->[1], which was seen before.\n"; |
|
|
127 | } else { |
125 | $buf .= " $about->[1], which is\n"; |
128 | $buf .= " $about->[1], which is\n"; |
126 | $track->(\$about->[1], $depth - 1, $indent + 1); |
129 | $track->(\$about->[1], $depth - 1, $about == $about[-1] ? "$indent " : "$indent| "); |
|
|
130 | } |
127 | } else { |
131 | } else { |
128 | $buf .= ".\n"; |
132 | $buf .= ".\n"; |
129 | } |
133 | } |
130 | } |
134 | } |
131 | } else { |
135 | } else { |
132 | $buf .= (" ") x $indent; |
|
|
133 | $buf .= "not found anywhere I looked :(\n"; |
136 | $buf .= "$indent not found anywhere I looked :(\n"; |
134 | } |
137 | } |
135 | } else { |
138 | } else { |
136 | $buf .= (" ") x $indent; |
|
|
137 | $buf .= "not referenced within the search depth.\n"; |
139 | $buf .= "$indent not referenced within the search depth.\n"; |
138 | } |
140 | } |
139 | }; |
141 | }; |
140 | |
142 | |
141 | $buf .= "$ref is\n"; |
143 | $buf .= "$ref is\n"; |
142 | $track->(\$ref, $depth || 10, 1); |
144 | $track->(\$ref, $depth || $ENV{PERL_DEVEL_FINDREF_DEPTH} || 10, ""); |
143 | $buf |
145 | $buf |
144 | } |
146 | } |
145 | |
147 | |
146 | =item @references = Devel::FindRef::find $ref |
148 | =item @references = Devel::FindRef::find $ref |
147 | |
149 | |
… | |
… | |
171 | # we know that HASH(0x176ff70) exists, so turn it into a hashref: |
173 | # we know that HASH(0x176ff70) exists, so turn it into a hashref: |
172 | my $ref_to_hash = Devel::FindRef::ptr2ref 0x176ff70; |
174 | my $ref_to_hash = Devel::FindRef::ptr2ref 0x176ff70; |
173 | |
175 | |
174 | =back |
176 | =back |
175 | |
177 | |
|
|
178 | =head1 ENVIRONMENT VARIABLES |
|
|
179 | |
|
|
180 | You can set the environment variable C<PERL_DEVEL_FINDREF_DEPTH> to an |
|
|
181 | integer to override the default depth in C<track>. If a call explicitly |
|
|
182 | specified a depth it is not overridden. |
|
|
183 | |
176 | =head1 AUTHOR |
184 | =head1 AUTHOR |
177 | |
185 | |
178 | Marc Lehmann <pcg@goof.com>. |
186 | Marc Lehmann <pcg@goof.com>. |
179 | |
187 | |
180 | =head1 BUGS |
188 | =head1 BUGS |