NAME
    Devel::FindRef - where is that reference to my variable hiding?

SYNOPSIS
      use Devel::FindRef;

DESCRIPTION
    Tracking down reference problems (e.g. you expect some object to be
    destroyed, but there are still references to it that keep it alive) can
    be very hard. Fortunately, perl keeps track of all its values, so
    tracking references "backwards" is usually possible.

    The "track" function can help track down some of those references back
    to the variables containing them.

    For example, for this fragment:

       package Test;           
                             
   our $var = "hi\n";
       my $x = \$var;      
       our %hash = (ukukey => \$var);
       our $hash2 = {ukukey2 => \$var};
                               
   sub testsub {             
          my $local = $hash2;      
          print Devel::FindRef::track \$var;
       }                             
                                       
   testsub;

    The output is as follows (or similar to this, in case I forget to update
    the manpage after some changes):

       SCALAR(0x814ece8) is
       +- in the global $Test::var.
       +- referenced by REF(0x814f9e4), which is
       |     in the lexical '$x' in CODE(0x814ed78), which is
       |        the containing scope for CODE(0x820c4b0), which is
       |           in the global &Test::testsub.
       +- referenced by REF(0x814ed6c), which is
       |     in the member 'ukukey' of HASH(0x81da20c), which is
       |        in the global %Test::hash.
       +- referenced by REF(0x814ec28), which is
       |     not found anywhere I looked :(
       +- referenced by REF(0x814eb44), which is
             in the member 'ukukey2' of HASH(0x814f99c), which is
             +- referenced by REF(0x820c450), which is
             |     in the lexical '$local' in CODE(0x820c4b0), which was seen before.
             +- referenced by REF(0x820c204), which is
                   in the global $Test::hash2.

    It is a bit convoluted to read, but basically it says that the value
    stored in $var can be found:

    - in some variable $x whose origin is not known (I frankly have no idea
    why, hints accepted).
    - in the hash element with key "ukukey" in the hash stored in
    %Test::hash.
    - in the global variable named $Test::var.
    - in the hash element "ukukey2", in the hash in the my variable $local
    in the sub "Test::testsub" and also in the hash referenced by
    $Test::hash2.

EXPORTS
    None.

FUNCTIONS
    $string = Devel::FindRef::track $ref[, $depth]
        Track the perl value pointed to by $ref up to a depth of $depth and
        return a descriptive string. $ref can point at any perl value, be it
        anonymous sub, hash, array, scalar etc.

        This is the function you most often use.

    @references = Devel::FindRef::find $ref
        Return arrayrefs that contain [$message, $ref] pairs. The message
        describes what kind of reference was found and the $ref is the
        reference itself, which can be omitted if "find" decided to end the
        search. The returned references are all weak references.

        The "track" function uses this to find references to the value you
        are interested in and recurses on the returned references.

    $ref = Devel::FindRef::ptr2ref $integer
        Sometimes you know (from debugging output) the address of a perl
        scalar you are interested in (e.g. "HASH(0x176ff70)"). This function
        can be used to turn the address into a reference to that scalar. It
        is quite safe to call on valid addresses, but extremely dangerous to
        call on invalid ones.

           # we know that HASH(0x176ff70) exists, so turn it into a hashref:
           my $ref_to_hash = Devel::FindRef::ptr2ref 0x176ff70;

ENVIRONMENT VARIABLES
    You can set the environment variable "PERL_DEVEL_FINDREF_DEPTH" to an
    integer to override the default depth in "track". If a call explicitly
    specified a depth it is not overridden.

AUTHOR
    Marc Lehmann <pcg@goof.com>.

BUGS
    Only code values, arrays, hashes, scalars and magic are being looked at.

    This is a quick hack only.

COPYRIGHT AND LICENSE
    Copyright (C) 2007 by Marc Lehmann.

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself, either Perl version 5.8.8 or, at
    your option, any later version of Perl 5 you may have available.

