blib/lib/DBIx/Class/QueryLog/Tee.pm

filter: Statementstmt 100% 40 / 40 Branchbran 85.7% 12 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 12 / 12 Podpod 75.0% 3 / 4 totaltotal 90.6% 68 / 75 CC 12 SCAR 10.3
CC
12
Cov
93%
__ANON__
5.7
add_logger
3.0
_valid_logger
3.0
CRAP 2.8
↑ Summary
1 package DBIx::Class::QueryLog::Tee;
2 1 $DBIx::Class::QueryLog::Tee::VERSION = '0.001000';
3 # ABSTRACT: Log to multiple QueryLogs at a time
4  
5 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings NONFATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Sub::Name 'subname';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 my @methods = qw(
11 txn_begin txn_commit txn_rollback
12 svp_begin svp_release svp_rollback
13 query_start query_end
14 );
15 10 ▶sub _valid_logger { !$_[0]->can($_) && return 0 for @methods; 1 }
Subroutine _valid_logger: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->can($_) or return 0 3 74 77
16  
17 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 has _loggers => (
20 is => 'ro',
21 isa => sub {
22 6 ▶ die "loggers has to be a hashref"
Subroutine __ANON__: called CC=5 SCAR=17.4
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] and ref $_[0] eq "HASH" 0 6 6
Condition33%1/3
ref $_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
006
MC/DC0%0/2
ref $_[0] and ref $_[0] eq "HASH"
ref $_[0] ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= ref $_[0]B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
23 unless ref $_[0] && ref $_[0] eq 'HASH';
24 !_valid_logger($_[0]->{$_}) && die "\$loggers->{$_} does not point to a valid logger"
25 6 ▶ for keys %{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
_valid_logger($_[0]{$_}) or die "\$loggers->{$_} does not point to a valid logger" 1 4 5
26 },
27 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
28 1 init_arg => 'loggers',
29 );
30  
31 sub add_logger {
32 2 ▶ my ($self, $name, $logger) = @_;
Subroutine add_logger: called CC=3 SCAR=11.0
Pod documented
33  
34 2 ▶ die "$name is not a valid logger" unless _valid_logger($logger);
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_logger($logger) 1 1 2
35  
36 die "Logger $name is already in the list"
37 1 ▶ if $self->_loggers->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_loggers->{$name} 0 1 1
38  
39 1 $self->_loggers->{$name} = $logger
40 }
41  
42 sub remove_logger {
43 2 ▶ my ($self, $name) = @_;
Subroutine remove_logger: called CC=2 SCAR=6.9
Pod documented
44  
45 2 ▶ die "unknown logger $name" unless $self->_loggers->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_loggers->{$name} 1 1 2
46  
47 1 delete $self->_loggers->{$name}
48 }
49  
50 sub replace_logger {
51 3 ▶ die "that is not a valid logger" unless _valid_logger($_[2]);
Subroutine replace_logger: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_logger($_[2]) 1 2 3
52  
53 2 $_[0]->_loggers->{$_[1]} = $_[2]
54 }
55  
56 1 for my $method (@methods) {
57 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
58 8 *{$method} = subname $method => sub {
59 2 ▶ my $self = shift;
Subroutine txn_begin: called CC=2 SCAR=6.9
Pod undocumented
60  
61 2 $_->$method(@_) for
62 map $self->_loggers->{$_},
63 2 sort keys %{$self->_loggers};
64 8 };
65 }
66  
67 1 1;
68  
69 __END__
↑ Summary