From: Peter Rabbitson Date: Tue, 8 Jul 2014 00:46:14 +0000 (+0200) Subject: Break out the test tracer into a standalone file X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4faaf174b94290230f2ebb2cc5077bc11752f69c;p=dbsrgits%2FDBIx-Class-Historic.git Break out the test tracer into a standalone file --- diff --git a/t/lib/DBICTest/BaseSchema.pm b/t/lib/DBICTest/BaseSchema.pm index 5fb9022..cdc7a02 100644 --- a/t/lib/DBICTest/BaseSchema.pm +++ b/t/lib/DBICTest/BaseSchema.pm @@ -11,35 +11,19 @@ use DBICTest::Util::LeakTracer qw(populate_weakregistry assert_empty_weakregistr use DBICTest::Util 'local_umask'; use namespace::clean; -{ - package # moar hide - DBICTest::SQLTracerObj; - use base 'DBIx::Class::Storage::Statistics'; - - sub query_start { push @{$_[0]{sqlbinds}}, [ ($_[1] =~ /^\s*(\S+)/)[0], [ $_[1], @{ $_[2]||[] } ] ] } - - # who the hell came up with this API >:( - for my $txn (qw(begin rollback commit)) { - no strict 'refs'; - *{"txn_$txn"} = sub { push @{$_[0]{sqlbinds}}, [ uc $txn => [ uc $txn ] ] }; - } - - sub svp_begin { push @{$_[0]{sqlbinds}}, [ SAVEPOINT => [ "SAVEPOINT $_[1]" ] ] } - sub svp_release { push @{$_[0]{sqlbinds}}, [ RELEASE_SAVEPOINT => [ "RELEASE $_[1]" ] ] } - sub svp_rollback { push @{$_[0]{sqlbinds}}, [ ROLLBACK_TO_SAVEPOINT => [ "ROLLBACK TO $_[1]" ] ] } - -} - sub capture_executed_sql_bind { my ($self, $cref) = @_; $self->throw_exception("Expecting a coderef to run") unless ref $cref eq 'CODE'; + require DBICTest::SQLTracerObj; + # hack around stupid, stupid API no warnings 'redefine'; local *DBIx::Class::Storage::DBI::_format_for_trace = sub { $_[1] }; Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO; + local $self->storage->{debugcb}; local $self->storage->{debugobj} = my $tracer_obj = DBICTest::SQLTracerObj->new; local $self->storage->{debug} = 1; diff --git a/t/lib/DBICTest/SQLTracerObj.pm b/t/lib/DBICTest/SQLTracerObj.pm new file mode 100644 index 0000000..23baeb3 --- /dev/null +++ b/t/lib/DBICTest/SQLTracerObj.pm @@ -0,0 +1,21 @@ +package # moar hide + DBICTest::SQLTracerObj; + +use strict; +use warnings; + +use base 'DBIx::Class::Storage::Statistics'; + +sub query_start { push @{$_[0]{sqlbinds}}, [ ($_[1] =~ /^\s*(\S+)/)[0], [ $_[1], @{ $_[2]||[] } ] ] } + +# who the hell came up with this API >:( +for my $txn (qw(begin rollback commit)) { + no strict 'refs'; + *{"txn_$txn"} = sub { push @{$_[0]{sqlbinds}}, [ uc $txn => [ uc $txn ] ] }; +} + +sub svp_begin { push @{$_[0]{sqlbinds}}, [ SAVEPOINT => [ "SAVEPOINT $_[1]" ] ] } +sub svp_release { push @{$_[0]{sqlbinds}}, [ RELEASE_SAVEPOINT => [ "RELEASE $_[1]" ] ] } +sub svp_rollback { push @{$_[0]{sqlbinds}}, [ ROLLBACK_TO_SAVEPOINT => [ "ROLLBACK TO $_[1]" ] ] } + +1;