X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage.pm;h=e8bc77be0908ef1349873bf1fc58dc339da0309c;hb=fd323bf1046faa7de5a8c985268d80ec5b703361;hp=08ea155f3ca309ac150fd460e4030ac861c8ca35;hpb=20674fcd94984d0d2be09ecda7f3c22715468936;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage.pm b/lib/DBIx/Class/Storage.pm index 08ea155..e8bc77b 100644 --- a/lib/DBIx/Class/Storage.pm +++ b/lib/DBIx/Class/Storage.pm @@ -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. 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