Commit | Line | Data |
ee356d00 |
1 | package DBIx::Class::Storage::DBI::Replicated::WithDSN; |
2 | |
3 | use Moose::Role; |
0bd8e058 |
4 | use Scalar::Util 'reftype'; |
ee356d00 |
5 | requires qw/_query_start/; |
6 | |
7 | use namespace::clean -except => 'meta'; |
8 | |
9 | =head1 NAME |
10 | |
11 | DBIx::Class::Storage::DBI::Replicated::WithDSN - A DBI Storage Role with DSN |
12 | information in trace output |
13 | |
14 | =head1 SYNOPSIS |
15 | |
16 | This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>. |
d4daee7b |
17 | |
ee356d00 |
18 | =head1 DESCRIPTION |
19 | |
20 | This role adds C<DSN: > info to storage debugging output. |
21 | |
22 | =head1 METHODS |
23 | |
24 | This class defines the following methods. |
25 | |
26 | =head2 around: _query_start |
27 | |
28 | Add C<DSN: > to debugging output. |
29 | |
30 | =cut |
31 | |
32 | around '_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 | } |
ede99b9f |
44 | elsif (my $id = eval { $self->id }) { |
45 | "$op [$storage_type=$id]$rest"; |
46 | } |
0bd8e058 |
47 | else { |
48 | "$op [$storage_type]$rest"; |
49 | } |
50 | }; |
51 | |
52 | $self->$method($query, @bind); |
ee356d00 |
53 | }; |
54 | |
55 | =head1 ALSO SEE |
56 | |
57 | L<DBIx::Class::Storage::DBI> |
58 | |
59 | =head1 AUTHOR |
60 | |
61 | John Napiorkowski <john.napiorkowski@takkle.com> |
62 | |
63 | =head1 LICENSE |
64 | |
65 | You may distribute this code under the same terms as Perl itself. |
66 | |
67 | =cut |
68 | |
69 | 1; |