File Coverage

blib/lib/DBIx/Class/QueryLog/Conditional.pm
Criterion Covered Total %
statement 19 19 100.0
branch 2 2 100.0
condition n/a
subroutine 13 13 100.0
pod 0 8 0.0
total 34 42 80.9


line stmt bran cond sub pod time code
1             package DBIx::Class::QueryLog::Conditional;
2             $DBIx::Class::QueryLog::Conditional::VERSION = '0.001000';
3             # ABSTRACT: Disable QueryLogger instead of all query logging
4              
5 1     1   79554 use Moo;
  1         29297  
  1         6  
6 1     1   2362 use warnings NONFATAL => 'all';
  1         3  
  1         132  
7              
8 1     1   6 use Sub::Name 'subname';
  1         2  
  1         133  
9              
10             my @methods = qw(
11             txn_begin txn_commit txn_rollback
12             svp_begin svp_release svp_rollback
13             query_start query_end
14             );
15             sub _valid_logger { !$_[0]->can($_) && return 0 for @methods; 1 }
16              
17 1     1   1129 use namespace::clean;
  1         16424  
  1         8  
18              
19             has _logger => (
20             is => 'ro',
21             isa => sub { die 'not a valid logger' unless _valid_logger($_[0]) },
22             init_arg => 'logger',
23             required => 1,
24             );
25              
26             has enabled => (
27             is => 'rw',
28             default => 1,
29             );
30              
31             has _enabled_method => (
32             is => 'ro',
33             init_arg => 'enabled_method',
34             default => sub {
35             sub { shift->enabled }
36             },
37             );
38              
39             for my $method (@methods) {
40 1     1   770 no strict 'refs';
  1         1  
  1         122  
41             *{$method} = subname $method => sub {
42 8     8 0 23992 my $self = shift;
        8 0    
        8 0    
        8 0    
        8 0    
        8 0    
        8 0    
        8 0    
43              
44 8         22 my $m = $self->_enabled_method ;
45 8 100       20 return unless $self->$m;
46              
47 4         26 $self->_logger->$method(@_);
48             };
49             }
50              
51             1;
52              
53             __END__