X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Flib%2FTestApp.pm;fp=t%2Flib%2FTestApp.pm;h=20d12f787dd370956c4a3507f830ccc94b8d4523;hp=3d50a73f454f052b7b9f031a15d7557298bbf9e0;hb=964bf130533c001789a80ef193f03d5c5f3817eb;hpb=59b3e4d0df63749ee601113ce44be5b4340be2a8 diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm index 3d50a73..20d12f7 100644 --- a/t/lib/TestApp.pm +++ b/t/lib/TestApp.pm @@ -60,23 +60,35 @@ TestApp->config( # above ->setup so we have some generated methods to be double sure. has an_attribute_before_we_change_base_classes => ( is => 'ro'); -if ($::setup_leakchecker && try_load_class('CatalystX::LeakChecker')) { - with 'CatalystX::LeakChecker'; +if ($::setup_leakchecker) { + require Scalar::Util; + require Devel::Cycle; has leaks => ( is => 'ro', default => sub { [] }, ); -} -sub found_leaks { - my ($ctx, @leaks) = @_; - push @{ $ctx->leaks }, @leaks; -} + sub count_leaks { + my ($ctx) = @_; + return scalar @{ $ctx->leaks }; + } + + after finalize => sub { + my ($ctx) = @_; + my @leaks; + + my $weak_ctx = $ctx; + Scalar::Util::weaken $weak_ctx; + + Devel::Cycle::find_cycle($ctx, sub { + my ($path) = @_; + push @leaks, $path + if $path->[0]->[2] == $weak_ctx; + }); -sub count_leaks { - my ($ctx) = @_; - return scalar @{ $ctx->leaks }; + push @{ $ctx->leaks }, @leaks; + }; } TestApp->setup;