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 | |
ddcc02d1 |
7 | use DBIx::Class::_Util 'dbic_internal_try'; |
8 | |
fd323bf1 |
9 | use namespace::clean -except => 'meta'; |
ee356d00 |
10 | |
11 | =head1 NAME |
12 | |
13 | DBIx::Class::Storage::DBI::Replicated::WithDSN - A DBI Storage Role with DSN |
14 | information in trace output |
15 | |
16 | =head1 SYNOPSIS |
17 | |
18 | This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>. |
d4daee7b |
19 | |
ee356d00 |
20 | =head1 DESCRIPTION |
21 | |
22 | This role adds C<DSN: > info to storage debugging output. |
23 | |
24 | =head1 METHODS |
25 | |
26 | This class defines the following methods. |
27 | |
28 | =head2 around: _query_start |
29 | |
30 | Add C<DSN: > to debugging output. |
31 | |
32 | =cut |
33 | |
34 | around '_query_start' => sub { |
35 | my ($method, $self, $sql, @bind) = @_; |
0bd8e058 |
36 | |
ddcc02d1 |
37 | my $dsn = (dbic_internal_try { $self->dsn }) || $self->_dbi_connect_info->[0]; |
0bd8e058 |
38 | |
cda869a8 |
39 | my($op, $rest) = (($sql=~m/^(\w+)(.+)$/),'NOP', 'NO SQL'); |
1fa4a3e2 |
40 | my $storage_type = $self->can('active') ? 'REPLICANT' : 'MASTER'; |
41 | |
0bd8e058 |
42 | my $query = do { |
43 | if ((reftype($dsn)||'') ne 'CODE') { |
44 | "$op [DSN_$storage_type=$dsn]$rest"; |
45 | } |
ddcc02d1 |
46 | elsif (my $id = dbic_internal_try { $self->id }) { |
ede99b9f |
47 | "$op [$storage_type=$id]$rest"; |
48 | } |
0bd8e058 |
49 | else { |
50 | "$op [$storage_type]$rest"; |
51 | } |
52 | }; |
53 | |
54 | $self->$method($query, @bind); |
ee356d00 |
55 | }; |
56 | |
57 | =head1 ALSO SEE |
58 | |
59 | L<DBIx::Class::Storage::DBI> |
60 | |
a2bd3796 |
61 | =head1 FURTHER QUESTIONS? |
ee356d00 |
62 | |
a2bd3796 |
63 | Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>. |
ee356d00 |
64 | |
a2bd3796 |
65 | =head1 COPYRIGHT AND LICENSE |
ee356d00 |
66 | |
a2bd3796 |
67 | This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE> |
68 | by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can |
69 | redistribute it and/or modify it under the same terms as the |
70 | L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>. |
ee356d00 |
71 | |
72 | =cut |
73 | |
74 | 1; |