X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FReplicated%2FWithDSN.pm;h=50f4f8b6d6a6f64b1c29a2b17dc830cb429a987e;hb=52b420dd006f55aced42c669f49182890b8826ea;hp=405d157a0039c83454a7d14a4c0eac75f3b9b586;hpb=cda869a8afcef42813042caedb83d0a80b145ca0;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 405d157..50f4f8b 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm @@ -1,9 +1,11 @@ package DBIx::Class::Storage::DBI::Replicated::WithDSN; use Moose::Role; +use Scalar::Util 'reftype'; requires qw/_query_start/; use namespace::clean -except => 'meta'; +use Try::Tiny; =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,11 +32,25 @@ Add C to debugging output. around '_query_start' => sub { my ($method, $self, $sql, @bind) = @_; - my $dsn = $self->_dbi_connect_info->[0]; + + 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