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.26 by root, Sun Aug 30 14:39:23 2009 UTC vs.
Revision 1.31 by root, Sun May 18 18:44:08 2014 UTC

4 4
5use XSLoader; 5use XSLoader;
6use Scalar::Util; 6use Scalar::Util;
7 7
8BEGIN { 8BEGIN {
9 our $VERSION = '1.422'; 9 our $VERSION = '1.43';
10 XSLoader::load __PACKAGE__, $VERSION; 10 XSLoader::load __PACKAGE__, $VERSION;
11} 11}
12 12
13=head1 NAME 13=head1 NAME
14 14
30The C<track> function can help track down some of those references back to 30The C<track> function can help track down some of those references back to
31the variables containing them. 31the variables containing them.
32 32
33For example, for this fragment: 33For 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
112And all these account for six reference counts. 111And all these account for six reference counts.
113 112
114
115=head1 EXPORTS 113=head1 EXPORTS
116 114
117None. 115None.
118 116
119=head1 FUNCTIONS 117=head1 FUNCTIONS
124 122
125Track the perl value pointed to by C<$ref> up to a depth of C<$depth> and 123Track the perl value pointed to by C<$ref> up to a depth of C<$depth> and
126return a descriptive string. C<$ref> can point at any perl value, be it 124return a descriptive string. C<$ref> can point at any perl value, be it
127anonymous sub, hash, array, scalar etc. 125anonymous sub, hash, array, scalar etc.
128 126
129This is the function you most often use. 127This is the function you most likely want to use when tracking down
128references.
130 129
131=cut 130=cut
132 131
133sub find($); 132sub 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
202Sometimes you know (from debugging output) the address of a perl scalar 201Sometimes you know (from debugging output) the address of a perl value you
203you are interested in (e.g. C<HASH(0x176ff70)>). This function can be used 202are interested in (e.g. C<HASH(0x176ff70)>). This function can be used to
204to turn the address into a reference to that scalar. It is quite safe to 203turn the address into a reference to that value. It is quite safe to call
205call on valid addresses, but extremely dangerous to call on invalid ones. 204on valid addresses, but extremely dangerous to call on invalid ones. I<No
205checks whatsoever will be done>, so don't use this unless you really know
206the 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 $ref = Devel::FindRef::ref2ptr $reference 211=item $ptr = Devel::FindRef::ref2ptr $reference
211 212
212The opposite of C<ptr2ref>, above: returns the internal address of the 213The opposite of C<ptr2ref>, above: returns the internal address of the
213value pointed to by the passed reference. I<No checks whatsoever will be 214value pointed to by the passed reference. This function is safe to call on
214done>, so don't use this. 215anything, and returns the same value that a normal reference would if used
216in a numeric context.
215 217
216=back 218=back
217 219
218=head1 ENVIRONMENT VARIABLES 220=head1 ENVIRONMENT VARIABLES
219 221
220You can set the environment variable C<PERL_DEVEL_FINDREF_DEPTH> to an 222You can set the environment variable C<PERL_DEVEL_FINDREF_DEPTH> to an
221integer to override the default depth in C<track>. If a call explicitly 223integer to override the default depth in C<track>. If a call explicitly
222specified a depth it is not overridden. 224specifies a depth, it is not overridden.
223 225
224=head1 AUTHOR 226=head1 AUTHOR
225 227
226Marc Lehmann <pcg@goof.com>. 228Marc Lehmann <pcg@goof.com>.
227 229
228=head1 COPYRIGHT AND LICENSE 230=head1 COPYRIGHT AND LICENSE
229 231
230Copyright (C) 2007, 2008 by Marc Lehmann. 232Copyright (C) 2007, 2008, 2009, 2013 by Marc Lehmann.
231 233
232This library is free software; you can redistribute it and/or modify 234This library is free software; you can redistribute it and/or modify
233it under the same terms as Perl itself, either Perl version 5.8.8 or, 235it under the same terms as Perl itself, either Perl version 5.8.8 or,
234at your option, any later version of Perl 5 you may have available. 236at your option, any later version of Perl 5 you may have available.
235 237

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines