X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FTxnScopeGuard.pm;h=edf72057f280688edf67765def5f9e0f9393ab67;hb=757891ed5c4132d95e339212a5f66a2ee9fe4503;hp=18e2260553a86b627a0c8f89e685edb47142101e;hpb=5815ffb0e34dcd74af49581f65e1d5aa71779a6b;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/TxnScopeGuard.pm b/lib/DBIx/Class/Storage/TxnScopeGuard.pm index 18e2260..edf7205 100644 --- a/lib/DBIx/Class/Storage/TxnScopeGuard.pm +++ b/lib/DBIx/Class/Storage/TxnScopeGuard.pm @@ -3,8 +3,9 @@ package DBIx::Class::Storage::TxnScopeGuard; use strict; use warnings; use Try::Tiny; -use Scalar::Util qw/weaken blessed refaddr/; +use Scalar::Util qw(weaken blessed refaddr); use DBIx::Class; +use DBIx::Class::_Util qw(is_exception detected_reinvoked_destructor); use DBIx::Class::Carp; use namespace::clean; @@ -19,15 +20,19 @@ sub new { # we are starting with an already set $@ - in order for things to work we need to # be able to recognize it upon destruction - store its weakref # recording it before doing the txn_begin stuff - if (defined $@ and $@ ne '') { - $guard->{existing_exception_ref} = (ref $@ ne '') ? $@ : \$@; - weaken $guard->{existing_exception_ref}; + # + # FIXME FRAGILE - any eval that fails but *does not* rethrow between here + # and the unwind will trample over $@ and invalidate the entire mechanism + # There got to be a saner way of doing this... + if (is_exception $@) { + weaken( + $guard->{existing_exception_ref} = (ref($@) eq '') ? \$@ : $@ + ); } $storage->txn_begin; - $guard->{dbh} = $storage->_dbh; - weaken $guard->{dbh}; + weaken( $guard->{dbh} = $storage->_dbh ); bless $guard, ref $class || $class; @@ -45,6 +50,8 @@ sub commit { } sub DESTROY { + return if &detected_reinvoked_destructor; + my $self = shift; return if $self->{inactivated}; @@ -54,14 +61,12 @@ sub DESTROY { return unless $self->{dbh}; my $exception = $@ if ( - defined $@ - and - $@ ne '' + is_exception $@ and ( ! defined $self->{existing_exception_ref} or - refaddr( ref $@ eq '' ? \$@ : $@ ) != refaddr($self->{existing_exception_ref}) + refaddr( ref($@) eq '' ? \$@ : $@ ) != refaddr($self->{existing_exception_ref}) ) ); @@ -151,13 +156,15 @@ the transaction is rolled back, via L L. -=head1 AUTHOR +L by chocolateboy (inspiration for this module) -Ash Berlin, 2008. +=head1 FURTHER QUESTIONS? -Inspired by L by chocolateboy. +Check the list of L. -This module is free software. It may be used, redistributed and/or modified -under the same terms as Perl itself. +=head1 COPYRIGHT AND LICENSE -=cut +This module is free software L +by the L. You can +redistribute it and/or modify it under the same terms as the +L.