X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FReplicated%2FWithDSN.pm;h=7cab9a932912a1b95926dc9416304b73e5b2bb9f;hb=e398f77e59be21bfdb90087caa30a092c87df0d6;hp=69a3add4f5619fb729c952668604092589150482;hpb=ee356d004e088518205ac720b37c31a64c9cd861;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm b/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm index 69a3add..7cab9a9 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm @@ -1,6 +1,7 @@ package DBIx::Class::Storage::DBI::Replicated::WithDSN; use Moose::Role; +use Scalar::Util 'reftype'; requires qw/_query_start/; use namespace::clean -except => 'meta'; @@ -13,7 +14,7 @@ information in trace output =head1 SYNOPSIS This class is used internally by L. - + =head1 DESCRIPTION This role adds C info to storage debugging output. @@ -30,8 +31,25 @@ Add C to debugging output. around '_query_start' => sub { my ($method, $self, $sql, @bind) = @_; - my $dsn = $self->_dbi_connect_info->[0]; - $self->$method("DSN: $dsn SQL: $sql", @bind); + + my $dsn = eval { $self->dsn } || $self->_dbi_connect_info->[0]; + + my($op, $rest) = (($sql=~m/^(\w+)(.+)$/),'NOP', 'NO SQL'); + my $storage_type = $self->can('active') ? 'REPLICANT' : 'MASTER'; + + my $query = do { + if ((reftype($dsn)||'') ne 'CODE') { + "$op [DSN_$storage_type=$dsn]$rest"; + } + elsif (my $id = eval { $self->id }) { + "$op [$storage_type=$id]$rest"; + } + else { + "$op [$storage_type]$rest"; + } + }; + + $self->$method($query, @bind); }; =head1 ALSO SEE