… | |
… | |
30 | The C<track> function can help track down some of those references back to |
30 | The C<track> function can help track down some of those references back to |
31 | the variables containing them. |
31 | the variables containing them. |
32 | |
32 | |
33 | For example, for this fragment: |
33 | For example, for this fragment: |
34 | |
34 | |
35 | package Test; |
35 | package Test; |
36 | |
36 | |
37 | use Devel::FindRef; |
37 | use Devel::FindRef; |
38 | use Scalar::Util; |
38 | use Scalar::Util; |
39 | |
39 | |
40 | our $var = "hi\n"; |
40 | our $var = "hi\n"; |
41 | my $global_my = \$var; |
41 | my $global_my = \$var; |
42 | our %global_hash = (ukukey => \$var); |
42 | our %global_hash = (ukukey => \$var); |
43 | our $global_hashref = { ukukey2 => \$var }; |
43 | our $global_hashref = { ukukey2 => \$var }; |
44 | |
44 | |
45 | sub testsub { |
45 | sub testsub { |
46 | my $testsub_local = $global_hashref; |
46 | my $testsub_local = $global_hashref; |
47 | print Devel::FindRef::track \$var; |
47 | print Devel::FindRef::track \$var; |
48 | } |
48 | } |
49 | |
|
|
50 | |
49 | |
51 | my $closure = sub { |
50 | my $closure = sub { |
52 | my $closure_var = \$_[0]; |
51 | my $closure_var = \$_[0]; |
53 | Scalar::Util::weaken (my $weak_ref = \$var); |
52 | Scalar::Util::weaken (my $weak_ref = \$var); |
54 | testsub; |
53 | testsub; |
… | |
… | |
109 | |
108 | |
110 | =back |
109 | =back |
111 | |
110 | |
112 | And all these account for six reference counts. |
111 | And all these account for six reference counts. |
113 | |
112 | |
114 | |
|
|
115 | =head1 EXPORTS |
113 | =head1 EXPORTS |
116 | |
114 | |
117 | None. |
115 | None. |
118 | |
116 | |
119 | =head1 FUNCTIONS |
117 | =head1 FUNCTIONS |
… | |
… | |
124 | |
122 | |
125 | Track the perl value pointed to by C<$ref> up to a depth of C<$depth> and |
123 | Track the perl value pointed to by C<$ref> up to a depth of C<$depth> and |
126 | return a descriptive string. C<$ref> can point at any perl value, be it |
124 | return a descriptive string. C<$ref> can point at any perl value, be it |
127 | anonymous sub, hash, array, scalar etc. |
125 | anonymous sub, hash, array, scalar etc. |
128 | |
126 | |
129 | This is the function you most often use. |
127 | This is the function you most likely want to use when tracking down |
|
|
128 | references. |
130 | |
129 | |
131 | =cut |
130 | =cut |
132 | |
131 | |
133 | sub find($); |
132 | sub find($); |
134 | |
133 | |
… | |
… | |
220 | |
219 | |
221 | =head1 ENVIRONMENT VARIABLES |
220 | =head1 ENVIRONMENT VARIABLES |
222 | |
221 | |
223 | You can set the environment variable C<PERL_DEVEL_FINDREF_DEPTH> to an |
222 | You can set the environment variable C<PERL_DEVEL_FINDREF_DEPTH> to an |
224 | integer to override the default depth in C<track>. If a call explicitly |
223 | integer to override the default depth in C<track>. If a call explicitly |
225 | specified a depth it is not overridden. |
224 | specifies a depth, it is not overridden. |
226 | |
225 | |
227 | =head1 AUTHOR |
226 | =head1 AUTHOR |
228 | |
227 | |
229 | Marc Lehmann <pcg@goof.com>. |
228 | Marc Lehmann <pcg@goof.com>. |
230 | |
229 | |
231 | =head1 COPYRIGHT AND LICENSE |
230 | =head1 COPYRIGHT AND LICENSE |
232 | |
231 | |
233 | Copyright (C) 2007, 2008 by Marc Lehmann. |
232 | Copyright (C) 2007, 2008, 2009, 2013 by Marc Lehmann. |
234 | |
233 | |
235 | This library is free software; you can redistribute it and/or modify |
234 | This library is free software; you can redistribute it and/or modify |
236 | it under the same terms as Perl itself, either Perl version 5.8.8 or, |
235 | it under the same terms as Perl itself, either Perl version 5.8.8 or, |
237 | at your option, any later version of Perl 5 you may have available. |
236 | at your option, any later version of Perl 5 you may have available. |
238 | |
237 | |