Protect DBIC as best we can from the failure mode in 7cb35852
[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
ddcc02d1 7use DBIx::Class::_Util 'dbic_internal_try';
8
fd323bf1 9use namespace::clean -except => 'meta';
ee356d00 10
11=head1 NAME
12
13DBIx::Class::Storage::DBI::Replicated::WithDSN - A DBI Storage Role with DSN
14information in trace output
15
16=head1 SYNOPSIS
17
18This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>.
d4daee7b 19
ee356d00 20=head1 DESCRIPTION
21
22This role adds C<DSN: > info to storage debugging output.
23
24=head1 METHODS
25
26This class defines the following methods.
27
28=head2 around: _query_start
29
30Add C<DSN: > to debugging output.
31
32=cut
33
34around '_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
59L<DBIx::Class::Storage::DBI>
60
a2bd3796 61=head1 FURTHER QUESTIONS?
ee356d00 62
a2bd3796 63Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
ee356d00 64
a2bd3796 65=head1 COPYRIGHT AND LICENSE
ee356d00 66
a2bd3796 67This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
68by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
69redistribute it and/or modify it under the same terms as the
70L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
ee356d00 71
72=cut
73
741;