| 1 |
root |
1.2 |
NAME |
| 2 |
|
|
Devel::FindRef - where is that reference to my scalar hiding? |
| 3 |
|
|
|
| 4 |
|
|
SYNOPSIS |
| 5 |
|
|
use Devel::FindRef; |
| 6 |
|
|
|
| 7 |
|
|
DESCRIPTION |
| 8 |
|
|
Tracking down reference problems (e.g. you expect some object to be |
| 9 |
|
|
destroyed, but there are still references to it that keep it alive). can |
| 10 |
|
|
be very hard, although perl keeps track of all values. |
| 11 |
|
|
|
| 12 |
|
|
The "track" function can hlep track down some of those refernces back to |
| 13 |
|
|
the variables containing them. |
| 14 |
|
|
|
| 15 |
|
|
For example, for this fragment: |
| 16 |
|
|
|
| 17 |
|
|
package Test; |
| 18 |
|
|
|
| 19 |
|
|
our $var = "hi\n"; |
| 20 |
|
|
my $x = \$var; |
| 21 |
|
|
our %hash = (ukukey => \$var); |
| 22 |
|
|
our $hash2 = {ukukey2 => \$var}; |
| 23 |
|
|
|
| 24 |
|
|
sub testsub { |
| 25 |
|
|
my $local = $hash2; |
| 26 |
|
|
print Devel::FindRef::track \$var; |
| 27 |
|
|
} |
| 28 |
|
|
|
| 29 |
|
|
testsub; |
| 30 |
|
|
|
| 31 |
|
|
The output is as follows (or similar to htis, in case I forget to update |
| 32 |
|
|
the manpage afetr some changes): |
| 33 |
|
|
|
| 34 |
|
|
SCALAR(0x676fa0) is |
| 35 |
|
|
referenced by REF(0x676fb0), which is |
| 36 |
|
|
in the lexical '$x' in CODE(0x676370), which is |
| 37 |
|
|
not found anywhere I looked :( |
| 38 |
|
|
referenced by REF(0x676360), which is |
| 39 |
|
|
in the member 'ukukey' of HASH(0x756660), which is |
| 40 |
|
|
in the global %Test::hash. |
| 41 |
|
|
in the global $Test::var. |
| 42 |
|
|
referenced by REF(0x6760e0), which is |
| 43 |
|
|
in the member 'ukukey2' of HASH(0x676f30), which is |
| 44 |
|
|
referenced by REF(0x77bcf0), which is |
| 45 |
|
|
in the lexical '$local' in CODE(0x77bcb0), which is |
| 46 |
|
|
in the global &Test::testsub. |
| 47 |
|
|
referenced by REF(0x77bc80), which is |
| 48 |
|
|
in the global $Test::hash2. |
| 49 |
|
|
|
| 50 |
|
|
It is a bit convoluted to read, but basically it says that the value |
| 51 |
|
|
stored in $var can be found: |
| 52 |
|
|
|
| 53 |
|
|
- in some variable $x whose origin is not known (I frankly have no idea |
| 54 |
|
|
why, hints accepted). |
| 55 |
|
|
- in the hash element with key "ukukey" in the hash stored in |
| 56 |
|
|
%Test::hash. |
| 57 |
|
|
- in the global variable named $Test::var. |
| 58 |
|
|
- in the hash element "ukukey2", in the hash in the my variable $local |
| 59 |
|
|
in the sub "Test::testsub" and also in the hash referenced by |
| 60 |
|
|
$Test::hash2. |
| 61 |
|
|
|
| 62 |
|
|
EXPORTS |
| 63 |
|
|
None. |
| 64 |
|
|
|
| 65 |
|
|
FUNCTIONS |
| 66 |
|
|
$string = Devel::FindRef::track $ref[, $depth] |
| 67 |
|
|
Track the perl value pointed to by $ref up to a depth of $depth |
| 68 |
|
|
and return a descriptive string. $ref can point at any perl |
| 69 |
|
|
value, be it anonymous sub, hash, array, scalar etc. |
| 70 |
|
|
|
| 71 |
|
|
This is the function you most often use. |
| 72 |
|
|
|
| 73 |
|
|
@references = Devel::FindRef::find $ref |
| 74 |
|
|
Return arrayrefs that contain [$message, $ref] pairs. The |
| 75 |
|
|
message describes what kind of reference was found and the $ref |
| 76 |
|
|
is the reference itself, which cna be omitted if "find" decided |
| 77 |
|
|
to end the search. |
| 78 |
|
|
|
| 79 |
|
|
The "track" function uses this to find references to the value |
| 80 |
|
|
you are interested in and recurses on the returned references. |
| 81 |
|
|
|
| 82 |
|
|
$ref = Devel::FindRef::ref2ptr $ptr |
| 83 |
|
|
Sometimes you know (from debugging output) the address of a perl |
| 84 |
|
|
scalar you are interested in. This function can be used to turn |
| 85 |
|
|
the address into a reference to that scalar. It is quite safe to |
| 86 |
|
|
call on valid addresses, but extremely dangerous to call on |
| 87 |
|
|
invalid ones. |
| 88 |
|
|
|
| 89 |
|
|
AUTHOR |
| 90 |
|
|
Marc Lehmann <pcg@goof.com>. |
| 91 |
|
|
|
| 92 |
|
|
BUGS |
| 93 |
|
|
Only code values, arrays, hashes, scalars and magic are being looked |
| 94 |
|
|
at. |
| 95 |
|
|
|
| 96 |
|
|
COPYRIGHT AND LICENSE |
| 97 |
|
|
Copyright (C) 2007 by Marc Lehmann. |
| 98 |
|
|
|
| 99 |
|
|
This library is free software; you can redistribute it and/or modify |
| 100 |
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 |
| 101 |
|
|
or, at your option, any later version of Perl 5 you may have |
| 102 |
|
|
available. |
| 103 |
|
|
|