X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FReplicated%2FWithDSN.pm;h=f26eb3c21763148b5b106a79e3d01d09141c544b;hb=64ae166780d0cb2b9577e506da9b9b240c146d20;hp=7d43c85cb017bb8bb8f1aa39ab2944efb003c0db;hpb=1fa4a3e2bfb302892dd6d6fdc8991367e185d63a;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 7d43c85..f26eb3c 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm @@ -1,8 +1,10 @@ package DBIx::Class::Storage::DBI::Replicated::WithDSN; use Moose::Role; +use Scalar::Util 'reftype'; requires qw/_query_start/; +use Try::Tiny; use namespace::clean -except => 'meta'; =head1 NAME @@ -13,7 +15,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,12 +32,25 @@ Add C to debugging output. around '_query_start' => sub { my ($method, $self, $sql, @bind) = @_; - my $dsn = $self->_dbi_connect_info->[0]; - my($op, $rest) = ($sql=~m/^(\w+) (.+)$/); + my $dsn = (try { $self->dsn }) || $self->_dbi_connect_info->[0]; + + my($op, $rest) = (($sql=~m/^(\w+)(.+)$/),'NOP', 'NO SQL'); my $storage_type = $self->can('active') ? 'REPLICANT' : 'MASTER'; - $self->$method("$op [DSN_$storage_type=$dsn] $rest", @bind); + my $query = do { + if ((reftype($dsn)||'') ne 'CODE') { + "$op [DSN_$storage_type=$dsn]$rest"; + } + elsif (my $id = try { $self->id }) { + "$op [$storage_type=$id]$rest"; + } + else { + "$op [$storage_type]$rest"; + } + }; + + $self->$method($query, @bind); }; =head1 ALSO SEE