Take a copy instead of weakening in 5.8 leak workaround
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Pg.pm
index a67bc2f..dacfdb6 100644 (file)
@@ -6,7 +6,6 @@ use warnings;
 use base qw/DBIx::Class::Storage::DBI/;
 
 use Scope::Guard ();
-use Scalar::Util 'weaken';
 use Context::Preserve 'preserve_context';
 use DBIx::Class::Carp;
 use Try::Tiny;
@@ -31,10 +30,10 @@ sub with_deferred_fk_checks {
 
   $self->_do_query('SET CONSTRAINTS ALL DEFERRED');
 
-  weaken($self);
   return preserve_context {
+    my $inner_self = $self; # avoid nested closure leak on 5.8
     my $sg = Scope::Guard->new(sub {
-      $self->_do_query('SET CONSTRAINTS ALL IMMEDIATE');
+      $inner_self->_do_query('SET CONSTRAINTS ALL IMMEDIATE');
     });
     $sub->()
   } after => sub { $txn_scope_guard->commit };