X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FReplicated.pm;h=1024d47c8bfbdfaa97bb74c93565e4189986718b;hb=ed7ab0f4ce1a9118ea6285ee562ef003085a6b64;hp=930a3be51e5d0928cd6bbc56a19f08e226afe869;hpb=7803e57ad8daee28020676140ea6894c31e3112e;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index 930a3be..1024d47 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -16,6 +16,7 @@ use MooseX::Types::Moose qw/ClassName HashRef Object/; use Scalar::Util 'reftype'; use Hash::Merge; use List::Util qw/min max reduce/; +use Try::Tiny; use namespace::clean -except => 'meta'; @@ -650,7 +651,8 @@ sub execute_reliably { my @result; my $want_array = wantarray; - eval { + my $exception; + try { if($want_array) { @result = $coderef->(@args); } elsif(defined $want_array) { @@ -658,19 +660,14 @@ sub execute_reliably { } else { $coderef->(@args); } + } catch { + $self->throw_exception("coderef returned an error: $_"); + } finally { + ##Reset to the original state + $self->read_handler($current); }; - ##Reset to the original state - $self->read_handler($current); - - ##Exception testing has to come last, otherwise you might leave the - ##read_handler set to master. - - if($@) { - $self->throw_exception("coderef returned an error: $@"); - } else { - return $want_array ? @result : $result[0]; - } + return $want_array ? @result : $result[0]; } =head2 set_reliable_storage