DBIx::Class::Storage::DBI::Replicated::WithDSN - A DBI Storage Role with DSN


DBIx-Class documentation Contained in the DBIx-Class distribution.

Index


Code Index:

NAME

Top

DBIx::Class::Storage::DBI::Replicated::WithDSN - A DBI Storage Role with DSN information in trace output

SYNOPSIS

Top

This class is used internally by DBIx::Class::Storage::DBI::Replicated.

DESCRIPTION

Top

This role adds DSN: info to storage debugging output.

METHODS

Top

This class defines the following methods.

around: _query_start

Add DSN: to debugging output.

ALSO SEE

Top

DBIx::Class::Storage::DBI

AUTHOR

Top

John Napiorkowski <john.napiorkowski@takkle.com>

LICENSE

Top

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;