Subject: | Fix for objects which override stringify |
The attached (quick'n'dirty) patch fixes the problem you get with objects such as those in Test::Unit, where the stringify overload stops the parsing of the "$obj" working correctly:
Not passed an object at /usr/local/lib/perl5/site_perl/5.8.0/Test/Unit/Assertion/Boolean.pm line 20
Use of uninitialized value in exists at /nfs/team71/psg/mca/cvswork-badger/AniTrack/testlib/Devel/Leak/Object.pm line 105.
Requires Scalar::Util.
Thanks,
--- Devel/Leak/Object.pm~ 2004-09-20 06:53:39.000000000 +0100
+++ Devel/Leak/Object.pm 2005-05-24 15:11:18.000000000 +0100
@@ -74,6 +74,7 @@
our %destroy_orig;
use Data::Dumper;
+use Scalar::Util;
sub import {
for my $i (0..$#_) {
@@ -97,11 +98,7 @@
{
my $obj = shift;
- my ($class,$type,$addr) = "$obj" =~ /^
- ((?:\w|\:\:)+) # Stringification has pkg name
- =(ARRAY|HASH|SCALAR|GLOB|CODE) # type
- \((0x[0-9a-f]+)\) # and address
- /x or carp "Not passed an object";
+ my ($class,$type,$addr) = _getinfo($obj);
if (exists $tracked{$addr}) { # rebless of tracked object
$objcount{$tracked{$addr}}--;
}
@@ -125,13 +122,18 @@
}
}
+sub _getinfo {
+ my $obj = shift;
+ my @info = (Scalar::Util::blessed($obj),
+ sprintf("0x%X", Scalar::Util::refaddr($obj)),
+ Scalar::Util::reftype($obj));
+ carp "Not passed an object" unless defined $info[0];
+ return @info;
+}
+
sub _DESTROY_stub {
my ($obj) = @_;
- my ($class,$type,$addr) = "$obj" =~ /^
- ((?:\w|\:\:)+) # Stringification has pkg name
- =(ARRAY|HASH|SCALAR|GLOB|CODE) # type
- \((0x[0-9a-f]+)\) # and address
- /x or carp "Not passed an object";
+ my ($class,$type,$addr) = _getinfo($obj);
if (exists($objcount{$class})) {
$objcount{$class}--;
warn "Object count for $class negative ($objcount{$class})\n"