1package DBIx::Class::Storage::DBI::Replicated::WithDSN; 2 3use Moose::Role; 4use Scalar::Util 'reftype'; 5requires qw/_query_start/; 6 7use namespace::clean -except => 'meta'; 8 9=head1 NAME 10 11DBIx::Class::Storage::DBI::Replicated::WithDSN - A DBI Storage Role with DSN 12information in trace output 13 14=head1 SYNOPSIS 15 16This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>. 17 18=head1 DESCRIPTION 19 20This role adds C<DSN: > info to storage debugging output. 21 22=head1 METHODS 23 24This class defines the following methods. 25 26=head2 around: _query_start 27 28Add C<DSN: > to debugging output. 29 30=cut 31 32around '_query_start' => sub { 33 my ($method, $self, $sql, @bind) = @_; 34 35 my $dsn = eval { $self->dsn } || $self->_dbi_connect_info->[0]; 36 37 my($op, $rest) = (($sql=~m/^(\w+)(.+)$/),'NOP', 'NO SQL'); 38 my $storage_type = $self->can('active') ? 'REPLICANT' : 'MASTER'; 39 40 my $query = do { 41 if ((reftype($dsn)||'') ne 'CODE') { 42 "$op [DSN_$storage_type=$dsn]$rest"; 43 } 44 elsif (my $id = eval { $self->id }) { 45 "$op [$storage_type=$id]$rest"; 46 } 47 else { 48 "$op [$storage_type]$rest"; 49 } 50 }; 51 52 $self->$method($query, @bind); 53}; 54 55=head1 ALSO SEE 56 57L<DBIx::Class::Storage::DBI> 58 59=head1 AUTHOR 60 61John Napiorkowski <john.napiorkowski@takkle.com> 62 63=head1 LICENSE 64 65You may distribute this code under the same terms as Perl itself. 66 67=cut 68 691; 70