… | |
… | |
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.422'; |
9 | our $VERSION = 1.45; |
10 | XSLoader::load __PACKAGE__, $VERSION; |
10 | XSLoader::load __PACKAGE__, $VERSION; |
11 | } |
11 | } |
12 | |
12 | |
13 | =head1 NAME |
13 | =head1 NAME |
14 | |
14 | |
… | |
… | |
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 | |
… | |
… | |
197 | grep !($#$_ && exists $excl{ref2ptr $_->[1]}), @$about |
196 | grep !($#$_ && exists $excl{ref2ptr $_->[1]}), @$about |
198 | } |
197 | } |
199 | |
198 | |
200 | =item $ref = Devel::FindRef::ptr2ref $integer |
199 | =item $ref = Devel::FindRef::ptr2ref $integer |
201 | |
200 | |
202 | Sometimes you know (from debugging output) the address of a perl scalar |
201 | Sometimes you know (from debugging output) the address of a perl value you |
203 | you are interested in (e.g. C<HASH(0x176ff70)>). This function can be used |
202 | are interested in (e.g. C<HASH(0x176ff70)>). This function can be used to |
204 | to turn the address into a reference to that scalar. It is quite safe to |
203 | turn the address into a reference to that value. It is quite safe to call |
205 | call on valid addresses, but extremely dangerous to call on invalid ones. |
204 | on valid addresses, but extremely dangerous to call on invalid ones. I<No |
|
|
205 | checks whatsoever will be done>, so don't use this unless you really know |
|
|
206 | the value is the address of a valid perl value. |
206 | |
207 | |
207 | # we know that HASH(0x176ff70) exists, so turn it into a hashref: |
208 | # we know that HASH(0x176ff70) exists, so turn it into a hashref: |
208 | my $ref_to_hash = Devel::FindRef::ptr2ref 0x176ff70; |
209 | my $ref_to_hash = Devel::FindRef::ptr2ref 0x176ff70; |
209 | |
210 | |
210 | =item $ptr = Devel::FindRef::ref2ptr $reference |
211 | =item $ptr = Devel::FindRef::ref2ptr $reference |
211 | |
212 | |
212 | The opposite of C<ptr2ref>, above: returns the internal address of the |
213 | The opposite of C<ptr2ref>, above: returns the internal address of the |
213 | value pointed to by the passed reference. I<No checks whatsoever will be |
214 | value pointed to by the passed reference. This function is safe to call on |
214 | done>, so don't use this. |
215 | anything, and returns the same value that a normal reference would if used |
|
|
216 | in a numeric context. |
215 | |
217 | |
216 | =back |
218 | =back |
217 | |
219 | |
218 | =head1 ENVIRONMENT VARIABLES |
220 | =head1 ENVIRONMENT VARIABLES |
219 | |
221 | |
220 | 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 |
221 | 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 |
222 | specified a depth it is not overridden. |
224 | specifies a depth, it is not overridden. |
223 | |
225 | |
224 | =head1 AUTHOR |
226 | =head1 AUTHOR |
225 | |
227 | |
226 | Marc Lehmann <pcg@goof.com>. |
228 | Marc Lehmann <pcg@goof.com>. |
227 | |
229 | |
228 | =head1 COPYRIGHT AND LICENSE |
230 | =head1 COPYRIGHT AND LICENSE |
229 | |
231 | |
230 | Copyright (C) 2007, 2008 by Marc Lehmann. |
232 | Copyright (C) 2007, 2008, 2009, 2013 by Marc Lehmann. |
231 | |
233 | |
232 | 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 |
233 | 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, |
234 | 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. |
235 | |
237 | |