From: Ton Voon Date: Fri, 14 May 2010 23:29:52 +0000 (+0000) Subject: txn_do's eval => try X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bca6956d7eb1196ae767271688f915d7ab078a10;p=dbsrgits%2FDBIx-Class-Historic.git txn_do's eval => try --- diff --git a/lib/DBIx/Class/Exception.pm b/lib/DBIx/Class/Exception.pm index e8e9ff7..2bdfc8d 100644 --- a/lib/DBIx/Class/Exception.pm +++ b/lib/DBIx/Class/Exception.pm @@ -5,6 +5,7 @@ use warnings; use Carp::Clan qw/^DBIx::Class/; use Scalar::Util qw/blessed/; +use Try::Tiny; use overload '""' => sub { shift->{msg} }, @@ -42,7 +43,7 @@ C<$stacktrace> tells it to use L instead of L. DBIx::Class::Exception->throw('Foo'); - eval { ... }; DBIx::Class::Exception->throw($@) if $@; + try { ... } catch { DBIx::Class::Exception->throw(shift) } =cut @@ -54,9 +55,7 @@ sub throw { # 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); diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 0e1b103..a800954 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -776,30 +776,32 @@ sub txn_do { 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/;