Devel-LeakGuard-Object
view release on metacpan or search on metacpan
#!perl
use latest;
use Data::Dumper;
use Test::Differences;
use Test::More tests => 20;
use Devel::LeakGuard::Object::State;
use Devel::LeakGuard::Object qw( leakguard );
package Foo;
use strict;
use warnings;
sub new {
my ( $class, $name ) = @_;
return bless { name => $name }, $class;
}
package main;
@Bar::ISA = qw( Foo );
{
eval 'leakguard {}';
ok !$@, 'no error from bare leakguard' or diag $@;
}
{
my $leaks = {};
my $foo1 = Foo->new( '1foo1' );
my $bar1 = Bar->new( '1bar1' );
leakguard {
my $foo2 = Foo->new( '1foo2' );
}
on_leak => sub { $leaks = shift };
eq_or_diff $leaks, {}, 'no leaks';
}
{
my $leaks = {};
my $foo1 = Foo->new( '2foo1' );
my $bar1 = Bar->new( '2bar1' );
leakguard {
my $foo2 = Foo->new( '2foo2' );
$foo2->{me} = $foo2;
}
on_leak => sub { $leaks = shift };
eq_or_diff $leaks, { Foo => [ 0, 1 ] }, 'leaks';
}
# Some versions of Carp.pm/perl emit a full stop (".") after the line
# number and some don't. We're going to handle both cases here.
sub normalize_line_num
{
my ($w) = @_;
s/line \d+\.?/line #/g for @$w;
return;
( run in 0.728 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )