| DBIx-Class documentation | Contained in the DBIx-Class distribution. |
DBIx::Class::Storage::DBI::Replicated::WithDSN - A DBI Storage Role with DSN information in trace output
This class is used internally by DBIx::Class::Storage::DBI::Replicated.
This role adds DSN: info to storage debugging output.
This class defines the following methods.
Add DSN: to debugging output.
John Napiorkowski <john.napiorkowski@takkle.com>
You may distribute this code under the same terms as Perl itself.
| DBIx-Class documentation | Contained in the DBIx-Class distribution. |
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';
around '_query_start' => sub { my ($method, $self, $sql, @bind) = @_; 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'; 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); };
1;