Subject: | constructor return multiple values |
Date: | Tue, 21 Dec 2010 09:29:30 +1100 |
To: | bug-Test-Weaken [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
I made a mistake in a "constructor" and returned a list of refs instead
of a single one, like ret.pl below. I suppose I meant to return \@ret,
but instead returned @ret as a list.
On returning multiple values only the last one seems to be checked. In
ret.pl for example $circular_obj is leaky, but only detected if it's the
second in the @ret, not the first.
I wonder if Test::Weaken might either process multiple values returned,
or give an error if it's not allowed. If allowed then I suppose all the
values could be passed to the subsequent "destructor" call.
I see the current \($constructor->()) form in Test::Weaken::test() is
list context already (and eg. context.pl below), so there'd be no change
to the calling, just to what was done if the return is multiple values.
use strict;
use warnings;
use Test::Weaken;
print Test::Weaken->VERSION,"\n";
my $leaks = Test::Weaken::leaks
({ constructor => sub {
my $obj = [];
my $circular_obj = {};
$circular_obj->{'circular'} = $circular_obj;
my @ret = ($circular_obj, $obj);
return @ret;
},
});
print $leaks ? "leaky\n" : "no leaks\n";
if ($leaks) {
my $probes = $leaks->unfreed_proberefs;
print @$probes,"\n";
}
use strict;
use warnings;
use Test::Weaken;
print Test::Weaken->VERSION,"\n";
my $leaks = Test::Weaken::leaks
({ constructor => sub {
print wantarray(),"\n";
return [];
},
});