1) changed all 4 space indentation to 2 space style indents for replication code...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / TxnScopeGuard.pm
index 04978f9..ca7cad7 100644 (file)
@@ -1,4 +1,5 @@
-package DBIx::Class::Storage::TxnScopeGuard;
+package # Hide from pause for now - till we get it working
+  DBIx::Class::Storage::TxnScopeGuard;
 
 use strict;
 use warnings;
@@ -20,7 +21,24 @@ sub commit {
 sub DESTROY {
   my ($dismiss, $storage) = @{$_[0]};
 
-  $storage->txn_rollback unless $dismiss;
+  return if $dismiss;
+
+  my $exception = $@;
+  Carp::cluck("A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or an error - bad")
+    unless $exception; 
+  {
+    local $@;
+    eval { $storage->txn_rollback };
+    my $rollback_exception = $@;
+    if($rollback_exception) {
+      my $exception_class = "DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION";
+
+      $storage->throw_exception(
+        "Transaction aborted: ${exception}. "
+        . "Rollback failed: ${rollback_exception}"
+      ) unless $rollback_exception =~ /$exception_class/;
+    }
+  }
 }
 
 1;
@@ -29,7 +47,7 @@ __END__
 
 =head1 NAME
 
-DBIx::Class::Storage::TxnScopeGuard
+DBIx::Class::Storage::TxnScopeGuard - Experimental
 
 =head1 SYNOPSIS