Some stylistic test changes in preparation for next commits
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / BaseSchema.pm
index f51328c..12cb5b8 100644 (file)
@@ -7,6 +7,7 @@ use base qw(DBICTest::Base DBIx::Class::Schema);
 
 use Fcntl qw(:DEFAULT :seek :flock);
 use Time::HiRes 'sleep';
+use Scope::Guard ();
 use DBICTest::Util::LeakTracer qw(populate_weakregistry assert_empty_weakregistry);
 use DBICTest::Util 'local_umask';
 use namespace::clean;
@@ -23,10 +24,20 @@ sub capture_executed_sql_bind {
   local *DBIx::Class::Storage::DBI::_format_for_trace = sub { $_[1] };
   Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO;
 
+  # can not use local() due to an unknown number of storages
+  # (think replicated)
+  my $orig_states = { map
+    { $_ => $self->storage->$_ }
+    qw(debugcb debugobj debug)
+  };
+
+  my $sg = Scope::Guard->new(sub {
+    $self->storage->$_ ( $orig_states->{$_} ) for keys %$orig_states;
+  });
 
-  local $self->storage->{debugcb};
-  local $self->storage->{debugobj} = my $tracer_obj = DBICTest::SQLTracerObj->new;
-  local $self->storage->{debug} = 1;
+  $self->storage->debugcb(undef);
+  $self->storage->debugobj( my $tracer_obj = DBICTest::SQLTracerObj->new );
+  $self->storage->debug(1);
 
   local $Test::Builder::Level = $Test::Builder::Level + 2;
   $cref->();