Subject: | Wishlist: callbacks |
It would be nice if Devel::Leak::Object allowed me to specify a callback function to be called for
each object. The attached file is the little hack I applied for my debugging needs. Something
more general would be nice, though.
(On the other hand, if you could provide Devel::Cycle output as an option, that would be very
useful.)
Subject: | open_WfZ6fzYi.txt |
--- /Library/Perl/5.10.1/Devel/Leak/Object.pm 2010-06-15 20:43:34.000000000 -0700
+++ Devel/Leak/Object.pm 2011-12-02 14:37:10.000000000 -0800
@@ -79,7 +79,9 @@
($package, $srcfile, $srcline, $subroutine) = ($next_package, $next_srcfile, $next_srcline, $next_subroutine);
}
}
- $TRACKED{$address} = { class => $class, file => $srcfile, line => $srcline, package=>$package, subroutine=>$subroutine };
+ Scalar::Util::weaken((
+ $TRACKED{$address} = { class => $class, file => $srcfile, line => $srcline, package=>$package, subroutine=>$subroutine, object => $object }
+ )->{object});
# If needed, initialise the new class
unless ( $DESTROY_STUBBED{$class} ) {
@@ -227,6 +229,8 @@
$classes{$obj->{class}} ||= {};
my $line = $obj->{file}.' line: '.$obj->{line}; #.' ('.$obj->{package}.' -> '.$obj->{subroutine}.')';
$classes{$obj->{class}}->{$line}++;
+ use Devel::Cycle;
+ find_cycle($obj->{object});
}
foreach my $class (sort keys(%classes)) {
printf STDERR "%s\n", $class;