Slightly golf ::ResultSource::DESTROY and several weaken() calls
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / TxnScopeGuard.pm
index 583639f..f961c4e 100644 (file)
@@ -26,11 +26,9 @@ sub new {
   #
   # Deliberately *NOT* using is_exception - if someone left a misbehaving
   # antipattern value in $@, it's not our business to whine about it
-  if( defined $@ and length $@ ) {
-    weaken(
-      $guard->{existing_exception_ref} = (length ref $@) ? $@ : \$@
-    );
-  }
+  weaken(
+    $guard->{existing_exception_ref} = (length ref $@) ? $@ : \$@
+  ) if( defined $@ and length $@ );
 
   $storage->txn_begin;
 
@@ -82,7 +80,7 @@ sub DESTROY {
   return unless defined $_[0]->{dbh};
 
 
-  carp 'A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error. Rolling back.'
+  carp 'A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error. Rolling back'
     unless defined $current_exception;
 
 
@@ -105,6 +103,11 @@ sub DESTROY {
 
   $@ = $current_exception
     if DBIx::Class::_ENV_::UNSTABLE_DOLLARAT;
+
+  # Dummy NEXTSTATE ensuring the all temporaries on the stack are garbage
+  # collected before leaving this scope. Depending on the code above, this
+  # may very well be just a preventive measure guarding future modifications
+  undef;
 }
 
 1;