X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FTxnScopeGuard.pm;h=f686cce374ba7c62ef28c3768d7ae8dcd4348743;hb=7d216b101775c472b012b257d848f50d78b193c8;hp=7f93113ac7ea53025b22a8177305493539c88989;hpb=fd323bf1046faa7de5a8c985268d80ec5b703361;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/TxnScopeGuard.pm b/lib/DBIx/Class/Storage/TxnScopeGuard.pm index 7f93113..f686cce 100644 --- a/lib/DBIx/Class/Storage/TxnScopeGuard.pm +++ b/lib/DBIx/Class/Storage/TxnScopeGuard.pm @@ -4,13 +4,16 @@ use strict; use warnings; use Carp::Clan qw/^DBIx::Class/; use Try::Tiny; +use Scalar::Util qw/weaken/; use namespace::clean; sub new { my ($class, $storage) = @_; $storage->txn_begin; - bless [ 0, $storage ], ref $class || $class; + my $guard = bless [ 0, $storage, $storage->_dbh ], ref $class || $class; + weaken ($guard->[2]); + $guard; } sub commit { @@ -25,6 +28,10 @@ sub DESTROY { return if $dismiss; + # if our dbh is not ours anymore, the weakref will go undef + $storage->_preserve_foreign_dbh; + return unless $_[0]->[2]; + my $exception = $@; { @@ -34,7 +41,9 @@ sub DESTROY { unless $exception; my $rollback_exception; - try { $storage->txn_rollback } + # do minimal connectivity check due to weird shit like + # https://rt.cpan.org/Public/Bug/Display.html?id=62370 + try { $storage->_seems_connected && $storage->txn_rollback } catch { $rollback_exception = shift }; if (defined $rollback_exception && $rollback_exception !~ /DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION/) {