Try::Tiny conversion finished
[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';
52b420dd 8use Try::Tiny;
ee356d00 9
10=head1 NAME
11
12DBIx::Class::Storage::DBI::Replicated::WithDSN - A DBI Storage Role with DSN
13information in trace output
14
15=head1 SYNOPSIS
16
17This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>.
d4daee7b 18
ee356d00 19=head1 DESCRIPTION
20
21This role adds C<DSN: > info to storage debugging output.
22
23=head1 METHODS
24
25This class defines the following methods.
26
27=head2 around: _query_start
28
29Add C<DSN: > to debugging output.
30
31=cut
32
33around '_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
58L<DBIx::Class::Storage::DBI>
59
60=head1 AUTHOR
61
62John Napiorkowski <john.napiorkowski@takkle.com>
63
64=head1 LICENSE
65
66You may distribute this code under the same terms as Perl itself.
67
68=cut
69
701;