From: Dagfinn Ilmari Mannsåker Date: Mon, 22 Dec 2014 19:48:15 +0000 (+0000) Subject: Take a copy instead of weakening in 5.8 leak workaround X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2aa3f4c0bc1ce479776c96a1bc7bb44f7cfd1233;p=dbsrgits%2FDBIx-Class.git Take a copy instead of weakening in 5.8 leak workaround I can't see a way $self could be the only strong reference to the object: either $_[0] or some other copy would have to be strong in order to have something to call the method on in the first place. However, let's not have everyone reading or editing the code have to do that reasoning. --- diff --git a/lib/DBIx/Class/Storage/DBI/Informix.pm b/lib/DBIx/Class/Storage/DBI/Informix.pm index b4a2ea8..cab66da 100644 --- a/lib/DBIx/Class/Storage/DBI/Informix.pm +++ b/lib/DBIx/Class/Storage/DBI/Informix.pm @@ -6,7 +6,6 @@ use base qw/DBIx::Class::Storage::DBI/; use mro 'c3'; use Scope::Guard (); -use Scalar::Util 'weaken'; use Context::Preserve 'preserve_context'; use namespace::clean; @@ -67,10 +66,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 }; diff --git a/lib/DBIx/Class/Storage/DBI/Pg.pm b/lib/DBIx/Class/Storage/DBI/Pg.pm index a67bc2f..dacfdb6 100644 --- a/lib/DBIx/Class/Storage/DBI/Pg.pm +++ b/lib/DBIx/Class/Storage/DBI/Pg.pm @@ -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 };