Devel-FindRef
view release on metacpan or search on metacpan
Revision history for Perl extension Devel::FindRef
TODO: unwrap the save stack to find mortalised scalars (too version dependent).
TODO: hash keys containing \x00 do not display properly.
TODO: get the stack of non-running coroutines?
TODO: And, there's one more thing.. The `sub THREE` in t/02_array_hash_weaken.t
TODO: is reported as
TODO: `CODE(0xb92810) [refcount 1], which is the global &main::THREE`
TODO: on perl-5.20.3 or earlier versions, and reported as
TODO: `CODE(0x1517c60) [refcount 1], which is referenced by REF(0x1518038)
TODO: [refcount 2], which is the hash member 'THREE' of HASH(0x14f2fe0) [refcount
TODO: 2], which is the global %main::main::`
TODO: on perl-5.22.3 or later versions. It makes me a little unhappy, but it's
TODO: still acceptable to me~
1.46 Sun Aug 5 13:28:55 CEST 2018
- work around API changes on debug perls, reported by various people.
1.45 Fri Jun 23 20:27:07 CEST 2017
- port to 5.22 and maybe later versions, mostly based on the
patch by Cindy Wang.
- added t/02_array_hash_weaken.t test case by Cindy Wang.
- bumped minimum version to 5.008003.
- added Canary::Stability, so minimum version doesn't keep it from
compiling with older versions.
1.44 Tue Jun 3 20:40:13 CEST 2014
- port to 5.20 (analyzed by Dave Mitchell).
1.43 Fri May 16 09:43:01 CEST 2014
- port to 5.18.
- hopefully better treat anon subs that have been un-anonized
- add some visual clues to the output string.
- look into anonymous closures to see where they were cloned.
- introduce PERL_DEVEL_FINDREF_DEPTH env variable.
1.2 Sat Apr 26 05:14:58 CEST 2008
- apply lots of fixes by Chris Heath.
- redo example in manpage, it's complete now.
1.1 Sat Dec 29 22:04:14 CET 2007
- ignore weak references.
- weaken internal references, to avoid displaying
them and drowning important output.
- properly find magical references.
1.0 Wed Nov 28 13:19:45 CET 2007
- correctly restore RMAGICAL flag (Ruslan Zakirov).
0.2 Wed Feb 7 22:31:58 CET 2007
- "backport" to 5.8.8.
0.1 Fri Jan 12 00:06:57 CET 2007
our %global_hash = (ukukey => \$var);
our $global_hashref = { ukukey2 => \$var };
sub testsub {
my $testsub_local = $global_hashref;
print Devel::FindRef::track \$var;
}
my $closure = sub {
my $closure_var = \$_[0];
Scalar::Util::weaken (my $weak_ref = \$var);
testsub;
};
$closure->($var);
The output is as follows (or similar to this, in case I forget to update
the manpage after some changes):
SCALAR(0x7cc888) [refcount 6] is
+- referenced by REF(0x8abcc8) [refcount 1], which is
"$_[0] [refcount " . (_refcnt $_[0]) . "]"
}
sub track {
my ($ref, $depth) = @_;
@_ = ();
my $buf = "";
my %seen;
Scalar::Util::weaken $ref;
my $track; $track = sub {
my ($refref, $depth, $indent) = @_;
if ($depth) {
my (@about) = find $$refref;
if (@about) {
for my $about (@about) {
$about->[0] =~ s/([^\x20-\x7e])/sprintf "\\{%02x}", ord $1/ge;
$buf .= "$indent" . (@about > 1 ? "+- " : "") . $about->[0];
#ifndef PadlistNAMES
# define PadlistNAMES(padlist) *PadlistARRAY (padlist)
#endif
#define res_pair(text) \
do { \
AV *av = newAV (); \
av_push (av, newSVpv (text, 0)); \
if (rmagical) SvRMAGICAL_on (sv); \
av_push (av, sv_rvweaken (newRV_inc (sv))); \
if (rmagical) SvRMAGICAL_off (sv); \
av_push (about, newRV_noinc ((SV *)av)); \
} while (0)
#define res_text(text) \
do { \
AV *av = newAV (); \
av_push (av, newSVpv (text, 0)); \
av_push (about, newRV_noinc ((SV *)av)); \
} while (0)
COPYING
Changes
Makefile.PL
MANIFEST
README
FindRef.xs
FindRef.pm
t/00_load.t
t/01_padarray.t
t/02_array_hash_weaken.t
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
our %global_hash = (ukukey => \$var);
our $global_hashref = { ukukey2 => \$var };
sub testsub {
my $testsub_local = $global_hashref;
print Devel::FindRef::track \$var;
}
my $closure = sub {
my $closure_var = \$_[0];
Scalar::Util::weaken (my $weak_ref = \$var);
testsub;
};
$closure->($var);
The output is as follows (or similar to this, in case I forget to update
the manpage after some changes):
SCALAR(0x7cc888) [refcount 6] is
+- referenced by REF(0x8abcc8) [refcount 1], which is
t/02_array_hash_weaken.t view on Meta::CPAN
BEGIN { $| = 1; print "1..4\n"; }
use Devel::FindRef;
use Scalar::Util qw(weaken);
my $y;
my @y = (2, \$y, [4, 5, \$y, \$y], {a => \$y});
weaken $y[2][2];
#print
Devel::FindRef::track \$y;
print "ok 1\n";
sub THREE { 3 }
#print
Devel::FindRef::track \THREE;
( run in 0.830 second using v1.01-cache-2.11-cpan-65fba6d93b7 )