… | |
… | |
4 | |
4 | |
5 | use XSLoader; |
5 | use XSLoader; |
6 | use Scalar::Util; |
6 | use Scalar::Util; |
7 | |
7 | |
8 | BEGIN { |
8 | BEGIN { |
9 | our $VERSION = '1.2'; |
9 | our $VERSION = '1.3'; |
10 | XSLoader::load __PACKAGE__, $VERSION; |
10 | XSLoader::load __PACKAGE__, $VERSION; |
11 | } |
11 | } |
12 | |
12 | |
13 | =head1 NAME |
13 | =head1 NAME |
14 | |
14 | |
15 | Devel::FindRef - where is that reference to my scalar hiding? |
15 | Devel::FindRef - where is that reference to my variable hiding? |
16 | |
16 | |
17 | =head1 SYNOPSIS |
17 | =head1 SYNOPSIS |
18 | |
18 | |
19 | use Devel::FindRef; |
19 | use Devel::FindRef; |
20 | |
20 | |
… | |
… | |
45 | testsub; |
45 | testsub; |
46 | |
46 | |
47 | The output is as follows (or similar to this, in case I forget to update |
47 | The output is as follows (or similar to this, in case I forget to update |
48 | the manpage after some changes): |
48 | the manpage after some changes): |
49 | |
49 | |
50 | SCALAR(0x7bd2d0) is |
50 | SCALAR(0x814ece8) is |
51 | in the global $Test::var. |
51 | +- in the global $Test::var. |
52 | referenced by REF(0x7bd240), which is |
52 | +- referenced by REF(0x814f9e4), which is |
53 | in the member 'ukukey2' of HASH(0x7bd228), which is |
|
|
54 | referenced by REF(0x81dae8), which is |
|
|
55 | in the lexical '$local' in CODE(0x81da88), which is |
53 | | in the lexical '$x' in CODE(0x814ed78), which is |
|
|
54 | | the containing scope for CODE(0x820c4b0), which is |
56 | in the global &Test::testsub. |
55 | | in the global &Test::testsub. |
|
|
56 | +- referenced by REF(0x814ed6c), which is |
|
|
57 | | in the member 'ukukey' of HASH(0x81da20c), which is |
|
|
58 | | in the global %Test::hash. |
|
|
59 | +- referenced by REF(0x814ec28), which is |
|
|
60 | | not found anywhere I looked :( |
|
|
61 | +- referenced by REF(0x814eb44), which is |
|
|
62 | in the member 'ukukey2' of HASH(0x814f99c), which is |
57 | referenced by REF(0x81da40), which is |
63 | +- referenced by REF(0x820c450), which is |
|
|
64 | | in the lexical '$local' in CODE(0x820c4b0), which was seen before. |
|
|
65 | +- referenced by REF(0x820c204), which is |
58 | in the global $Test::hash2. |
66 | in the global $Test::hash2. |
59 | referenced by REF(0x79f3f8), which is |
|
|
60 | in the lexical '$x' in CODE(0x79f518), which is |
|
|
61 | the containing scope for CODE(0x81da88), which is |
|
|
62 | in the global &Test::testsub. |
|
|
63 | referenced by REF(0x79f2f0), which is |
|
|
64 | not found anywhere I looked :( |
|
|
65 | referenced by REF(0x79f140), which is |
|
|
66 | in the member 'ukukey' of HASH(0x81d698), which is |
|
|
67 | in the global %Test::hash. |
|
|
68 | |
67 | |
69 | It is a bit convoluted to read, but basically it says that the value |
68 | It is a bit convoluted to read, but basically it says that the value |
70 | stored in C<$var> can be found: |
69 | stored in C<$var> can be found: |
71 | |
70 | |
72 | =over 4 |
71 | =over 4 |
… | |
… | |
118 | |
117 | |
119 | if ($depth) { |
118 | if ($depth) { |
120 | my (@about) = find $$refref; |
119 | my (@about) = find $$refref; |
121 | if (@about) { |
120 | if (@about) { |
122 | for my $about (@about) { |
121 | for my $about (@about) { |
123 | $buf .= (" ") x $indent; |
122 | $buf .= "$indent" . (@about > 1 ? "+- " : " ") . $about->[0]; |
124 | $buf .= $about->[0]; |
|
|
125 | if (@$about > 1) { |
123 | if (@$about > 1) { |
126 | if ($seen{$about->[1]+0}++) { |
124 | if ($seen{$about->[1]+0}++) { |
127 | $buf .= " $about->[1], which was seen before.\n"; |
125 | $buf .= " $about->[1], which was seen before.\n"; |
128 | } else { |
126 | } else { |
129 | $buf .= " $about->[1], which is\n"; |
127 | $buf .= " $about->[1], which is\n"; |
130 | $track->(\$about->[1], $depth - 1, $indent + 1); |
128 | $track->(\$about->[1], $depth - 1, $about == $about[-1] ? "$indent " : "$indent| "); |
131 | } |
129 | } |
132 | } else { |
130 | } else { |
133 | $buf .= ".\n"; |
131 | $buf .= ".\n"; |
134 | } |
132 | } |
135 | } |
133 | } |
136 | } else { |
134 | } else { |
137 | $buf .= (" ") x $indent; |
|
|
138 | $buf .= "not found anywhere I looked :(\n"; |
135 | $buf .= "$indent not found anywhere I looked :(\n"; |
139 | } |
136 | } |
140 | } else { |
137 | } else { |
141 | $buf .= (" ") x $indent; |
|
|
142 | $buf .= "not referenced within the search depth.\n"; |
138 | $buf .= "$indent not referenced within the search depth.\n"; |
143 | } |
139 | } |
144 | }; |
140 | }; |
145 | |
141 | |
146 | $buf .= "$ref is\n"; |
142 | $buf .= "$ref is\n"; |
147 | $track->(\$ref, $depth || 10, 1); |
143 | $track->(\$ref, $depth || $ENV{PERL_DEVEL_FINDREF_DEPTH} || 10, ""); |
148 | $buf |
144 | $buf |
149 | } |
145 | } |
150 | |
146 | |
151 | =item @references = Devel::FindRef::find $ref |
147 | =item @references = Devel::FindRef::find $ref |
152 | |
148 | |
… | |
… | |
176 | # we know that HASH(0x176ff70) exists, so turn it into a hashref: |
172 | # we know that HASH(0x176ff70) exists, so turn it into a hashref: |
177 | my $ref_to_hash = Devel::FindRef::ptr2ref 0x176ff70; |
173 | my $ref_to_hash = Devel::FindRef::ptr2ref 0x176ff70; |
178 | |
174 | |
179 | =back |
175 | =back |
180 | |
176 | |
|
|
177 | =head1 ENVIRONMENT VARIABLES |
|
|
178 | |
|
|
179 | You can set the environment variable C<PERL_DEVEL_FINDREF_DEPTH> to an |
|
|
180 | integer to override the default depth in C<track>. If a call explicitly |
|
|
181 | specified a depth it is not overridden. |
|
|
182 | |
181 | =head1 AUTHOR |
183 | =head1 AUTHOR |
182 | |
184 | |
183 | Marc Lehmann <pcg@goof.com>. |
185 | Marc Lehmann <pcg@goof.com>. |
184 | |
186 | |
185 | =head1 BUGS |
187 | =head1 BUGS |