Port ::Replicated from Moose to Moo+Type::Tiny
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Replicated / WithDSN.pm
CommitLineData
ee356d00 1package DBIx::Class::Storage::DBI::Replicated::WithDSN;
2
1e1cc55e 3use Moo::Role;
0bd8e058 4use Scalar::Util 'reftype';
ee356d00 5requires qw/_query_start/;
6
52b420dd 7use Try::Tiny;
1e1cc55e 8use namespace::clean;
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
a2bd3796 60=head1 FURTHER QUESTIONS?
ee356d00 61
a2bd3796 62Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
ee356d00 63
a2bd3796 64=head1 COPYRIGHT AND LICENSE
ee356d00 65
a2bd3796 66This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
67by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
68redistribute it and/or modify it under the same terms as the
69L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
ee356d00 70
71=cut
72
731;