File Coverage

blib/lib/SQL/Translator/Role/Debug.pm
Criterion Covered Total %
statement 18 19 94.7
branch 1 2 50.0
condition 0 3 0.0
subroutine 6 6 100.0
pod 0 1 0.0
total 25 31 80.6


line stmt bran cond sub pod time code
1             package SQL::Translator::Role::Debug;
2 71     71   48531 use Moo::Role;
  71         189  
  71         711  
3 71     71   46118 use Sub::Quote qw(quote_sub);
  71         188  
  71         9538  
4              
5             has _DEBUG => (
6             is => 'rw',
7             accessor => 'debugging',
8             init_arg => 'debugging',
9             coerce => quote_sub(q{ $_[0] ? 1 : 0 }),
10             lazy => 1,
11             builder => 1,
12             );
13              
14             sub _build__DEBUG {
15 142     142   5158 my ($self) = @_;
16 142         440 my $class = ref $self;
17 71     71   502 no strict 'refs';
  71         169  
  71         10069  
18 142         323 return ${"${class}::DEBUG"};
  142         3798  
19             }
20              
21             around debugging => sub {
22             my ($orig, $self) = (shift, shift);
23              
24             # Emulate horrible Class::Base API
25             unless (ref $self) {
26 71     71   503 my $dbgref = do { no strict 'refs'; \${"${self}::DEBUG"} };
  71         217  
  71         16291  
27             $$dbgref = $_[0] if @_;
28             return $$dbgref;
29             }
30             return $self->$orig(@_);
31             };
32              
33             sub debug {
34 929     929 0 1977 my $self = shift;
35              
36 929 50       26067 return unless $self->debugging;
37              
38 0   0       print STDERR '[', (ref $self || $self), '] ', @_, "\n";
39             }
40              
41             1;