[Bast-commits] r9378 - in DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class: . Storage

tonvoon at dev.catalyst.perl.org tonvoon at dev.catalyst.perl.org
Fri May 14 23:29:52 GMT 2010


Author: tonvoon
Date: 2010-05-15 00:29:52 +0100 (Sat, 15 May 2010)
New Revision: 9378

Modified:
   DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Exception.pm
   DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Storage/DBI.pm
Log:
txn_do's eval => try


Modified: DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Exception.pm
===================================================================
--- DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Exception.pm	2010-05-14 22:45:27 UTC (rev 9377)
+++ DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Exception.pm	2010-05-14 23:29:52 UTC (rev 9378)
@@ -5,6 +5,7 @@
 
 use Carp::Clan qw/^DBIx::Class/;
 use Scalar::Util qw/blessed/;
+use Try::Tiny;
 
 use overload
     '""' => sub { shift->{msg} },
@@ -42,7 +43,7 @@
 L<Carp::Clan/croak>.
 
   DBIx::Class::Exception->throw('Foo');
-  eval { ... }; DBIx::Class::Exception->throw($@) if $@;
+  try { ... } catch { DBIx::Class::Exception->throw(shift) }
 
 =cut
 
@@ -54,9 +55,7 @@
 
     # use Carp::Clan's croak if we're not stack tracing
     if(!$stacktrace) {
-        local $@;
-        eval { croak $msg };
-        $msg = $@
+        try { croak $msg } catch { $msg = shift };
     }
     else {
         $msg = Carp::longmess($msg);

Modified: DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Storage/DBI.pm	2010-05-14 22:45:27 UTC (rev 9377)
+++ DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Storage/DBI.pm	2010-05-14 23:29:52 UTC (rev 9378)
@@ -776,30 +776,32 @@
 
   my $tried = 0;
   while(1) {
-    eval {
+    my $exception;
+    my @args = @_;
+    try {
       $self->_get_dbh;
 
       $self->txn_begin;
       if($want_array) {
-          @result = $coderef->(@_);
+          @result = $coderef->(@args);
       }
       elsif(defined $want_array) {
-          $result[0] = $coderef->(@_);
+          $result[0] = $coderef->(@args);
       }
       else {
-          $coderef->(@_);
+          $coderef->(@args);
       }
       $self->txn_commit;
+    } catch {
+      $exception = $_;
     };
 
-    # ->connected might unset $@ - copy
-    my $exception = $@;
-    if(!$exception) { return $want_array ? @result : $result[0] }
+    if(! defined $exception) { return $want_array ? @result : $result[0] }
 
     if($tried++ || $self->connected) {
-      eval { $self->txn_rollback };
-      my $rollback_exception = $@;
-      if($rollback_exception) {
+      my $rollback_exception;
+      try { $self->txn_rollback } catch { $rollback_exception = shift };
+      if(defined $rollback_exception) {
         my $exception_class = "DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION";
         $self->throw_exception($exception)  # propagate nested rollback
           if $rollback_exception =~ /$exception_class/;




More information about the Bast-commits mailing list