support coderef connect_infos for repicated storage
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Replicated / WithDSN.pm
CommitLineData
ee356d00 1package DBIx::Class::Storage::DBI::Replicated::WithDSN;
2
3use Moose::Role;
0bd8e058 4use Scalar::Util 'reftype';
ee356d00 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>.
d4daee7b 17
ee356d00 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) = @_;
0bd8e058 34
35 my $dsn = eval { $self->dsn } || $self->_dbi_connect_info->[0];
36
cda869a8 37 my($op, $rest) = (($sql=~m/^(\w+)(.+)$/),'NOP', 'NO SQL');
1fa4a3e2 38 my $storage_type = $self->can('active') ? 'REPLICANT' : 'MASTER';
39
0bd8e058 40 my $query = do {
41 if ((reftype($dsn)||'') ne 'CODE') {
42 "$op [DSN_$storage_type=$dsn]$rest";
43 }
44 else {
45 "$op [$storage_type]$rest";
46 }
47 };
48
49 $self->$method($query, @bind);
ee356d00 50};
51
52=head1 ALSO SEE
53
54L<DBIx::Class::Storage::DBI>
55
56=head1 AUTHOR
57
58John Napiorkowski <john.napiorkowski@takkle.com>
59
60=head1 LICENSE
61
62You may distribute this code under the same terms as Perl itself.
63
64=cut
65
661;