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