use namespace::clean w/ Try::Tiny
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage.pm
index 08ea155..e8bc77b 100644 (file)
@@ -10,6 +10,8 @@ use DBIx::Class::Exception;
 use Scalar::Util();
 use IO::File;
 use DBIx::Class::Storage::TxnScopeGuard;
+use Try::Tiny;
+use namespace::clean;
 
 __PACKAGE__->mk_group_accessors('simple' => qw/debug debugobj schema/);
 __PACKAGE__->mk_group_accessors('inherited' => 'cursor_class');
@@ -161,9 +163,10 @@ For example,
   try {
     $rs = $schema->txn_do($coderef);
   } catch {
+    my $error = shift;
     # Transaction failed
     die "something terrible has happened!"   #
-      if ($@ =~ /Rollback failed/);          # Rollback failed
+      if ($error =~ /Rollback failed/);          # Rollback failed
 
     deal_with_failed_transaction();
   };
@@ -194,7 +197,7 @@ sub txn_do {
   $self->txn_begin; # If this throws an exception, no rollback is needed
 
   my $wantarray = wantarray; # Need to save this since the context
-                             # inside the eval{} block is independent
+                             # inside the try{} block is independent
                              # of the context that called txn_do()
   try {
 
@@ -211,23 +214,23 @@ sub txn_do {
       $coderef->(@args);
     }
     $self->txn_commit;
-  } catch {
-    my $error = $@;
+  }
+  catch {
+    my $error = shift;
 
     try {
       $self->txn_rollback;
     } catch {
-      my $rollback_error = $@;
       my $exception_class = "DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION";
       $self->throw_exception($error)  # propagate nested rollback
-        if $rollback_error =~ /$exception_class/;
+        if $_ =~ /$exception_class/;
 
       $self->throw_exception(
-        "Transaction aborted: $error. Rollback failed: ${rollback_error}"
+        "Transaction aborted: $error. Rollback failed: $_"
       );
     }
     $self->throw_exception($error); # txn failed but rollback succeeded
-  }
+  };
 
   return $wantarray ? @return_values : $return_value;
 }
@@ -477,8 +480,8 @@ If the value is of the form C<1=/path/name> then the trace output is
 written to the file C</path/name>.
 
 This environment variable is checked when the storage object is first
-created (when you call connect on your schema).  So, run-time changes 
-to this environment variable will not take effect unless you also 
+created (when you call connect on your schema).  So, run-time changes
+to this environment variable will not take effect unless you also
 re-connect on your schema.
 
 =head2 DBIX_CLASS_STORAGE_DBI_DEBUG