include our own leak checking code rather than using CatalystX::LeakCheck
Graham Knop [Fri, 19 Jun 2020 21:33:19 +0000 (23:33 +0200)]
Most of CatalystX::LeakCheck is related to formatting output. We can
inline the bit we need for the tests, which eliminates a circular
dependency for developers.

Makefile.PL
t/lib/TestApp.pm
t/live_component_controller_context_closure.t

index c0ef18f..cfe61ef 100644 (file)
@@ -84,7 +84,6 @@ my %META = (
     },
     develop   => {
       requires => {
-        'CatalystX::LeakChecker'  => '0.05',
         'Test::TCP'               => '2.00',
         'File::Copy::Recursive'   => '0.40',
         'Starman'                 => 0,
index 3d50a73..20d12f7 100644 (file)
@@ -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;
index 69fa504..ff0bbe9 100644 (file)
@@ -3,8 +3,8 @@ use warnings;
 use Test::More;
 
 BEGIN {
-    unless (eval 'use CatalystX::LeakChecker 0.05; 1') {
-        plan skip_all => 'CatalystX::LeakChecker 0.05 required for this test';
+    unless (eval 'use Devel::Cycle 1.11; 1') {
+        plan skip_all => 'Devel::Cycle 1.11 required for this test';
     }
 
     plan tests => 6;