Fix leak of $sth during populate() on perls < 5.10
[dbsrgits/DBIx-Class.git] / t / 52cycle.t
index 145ad92..d3d88d5 100644 (file)
@@ -5,15 +5,15 @@ use Test::More;
 use lib qw(t/lib);
 
 BEGIN {
-  eval { require Test::Memory::Cycle; require Devel::Cycle };
-  if ($@ or Devel::Cycle->VERSION < 1.10) {
-    plan skip_all => "leak test needs Test::Memory::Cycle and Devel::Cycle >= 1.10";
-  };
+  require DBIx::Class;
+  plan skip_all => 'Test needs: ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_cycle')
+    unless ( DBIx::Class::Optional::Dependencies->req_ok_for ('test_cycle') );
 }
 
 use DBICTest;
 use DBICTest::Schema;
-use Scalar::Util ();
+use Scalar::Util 'weaken';
+use namespace::clean;
 
 import Test::Memory::Cycle;
 
@@ -21,8 +21,12 @@ my $weak;
 
 {
   my $s = $weak->{schema} = DBICTest->init_schema;
+  ok ($s->storage->connected, 'we are connected');
   memory_cycle_ok($s, 'No cycles in schema');
 
+  my $storage = $weak->{storage} = $s->storage;
+  memory_cycle_ok($storage, 'No cycles in storage');
+
   my $rs = $weak->{resultset} = $s->resultset ('Artist');
   memory_cycle_ok($rs, 'No cycles in resultset');
 
@@ -32,7 +36,17 @@ my $weak;
   my $row = $weak->{row} = $rs->first;
   memory_cycle_ok($row, 'No cycles in row');
 
-  Scalar::Util::weaken ($_) for values %$weak;
+  my $sqla = $weak->{sqla} = $s->storage->sql_maker;
+  memory_cycle_ok($sqla, 'No cycles in SQL maker');
+
+  my $dbh = $weak->{dbh} = $s->storage->_get_dbh;
+  memory_cycle_ok($dbh, 'No cycles in DBI handle');
+
+  for (@{$dbh->{ChildHandles}}) {
+    $weak->{"$_"} = $_ if $_;
+  }
+
+  weaken $_ for values %$weak;
   memory_cycle_ok($weak, 'No cycles in weak object collection');
 }