Fix incorrect exception propagation in ::Replicated::execute_reliably
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Replicated.pm
index 8328cf3..512c53e 100644 (file)
@@ -21,6 +21,7 @@ use Hash::Merge;
 use List::Util qw/min max reduce/;
 use Context::Preserve 'preserve_context';
 use Try::Tiny;
+use DBIx::Class::_Util 'dbic_internal_try';
 
 use namespace::clean -except => 'meta';
 
@@ -375,7 +376,8 @@ my $method_dispatch = {
   )],
 };
 
-if (DBIx::Class::_ENV_::DBICTEST) {
+# this only happens during DBIC-internal testing
+if ( $INC{"t/lib/ANFANG.pm"} ) {
 
   my $seen;
   for my $type (keys %$method_dispatch) {
@@ -691,19 +693,13 @@ sub execute_reliably {
   my $self = shift;
   my $coderef = shift;
 
-  unless( ref $coderef eq 'CODE') {
-    $self->throw_exception('Second argument must be a coderef');
-  }
+  $self->throw_exception('Second argument must be a coderef')
+    unless( ref $coderef eq 'CODE');
 
   ## replace the current read handler for the remainder of the scope
   local $self->{read_handler} = $self->master;
 
-  my $args = \@_;
-  return try {
-    $coderef->(@$args);
-  } catch {
-    $self->throw_exception("coderef returned an error: $_");
-  };
+  &$coderef;
 }
 
 =head2 set_reliable_storage