blib/lib/Log/Any/Adapter/Carp.pm

filter: Statementstmt 100% 73 / 73 Branchbran 84.6% 22 / 26 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 1 totaltotal 94.2% 114 / 121 SCAR 28.4
CC
17
Cov
95%
init
13.1
__ANON__
3.2
__ANON__
2.0
CRAP 17.0
↑ Summary Build »
1 #!perl
2 #
3  
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 package Log::Any::Adapter::Carp;
8  
9 3 our ($VERSION) = '1.02';
10 3 our (@CARP_NOT) = ( __PACKAGE__, 'Log::Any::Proxy' );
11  
12 3 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Log::Any::Adapter::Util 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use parent 'Log::Any::Adapter::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub init {
18 16 ▶ my ($self) = @_;
Subroutine init: called CC=13 SCAR=25.7
Pod undocumented
19 16 my $i = 1;
20 16 my $callpack;
21 my $logger;
22  
23 16 ▶ do { $callpack = caller( $i++ ) } while $callpack =~ /^Log::Any::/;
Branch: 1 branch
BranchTrueFalseTotal
$callpack =~ /^Log::Any::/ and do { do { $callpack = caller $i++ } } 60 16 76
24  
25 16 ▶ $self->{log_level} = 'trace' unless exists $self->{log_level};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"log_level"} 0 16 16
26 $self->{log_level} =
27 Log::Any::Adapter::Util::numeric_level( $self->{log_level} )
28 16 ▶ unless $self->{log_level} =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"log_level"} =~ /^\d+$/ 16 0 16
29  
30 16 ▶ if ( $self->{no_trace} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'no_trace'}) { } 1 15 16
elsif ($self->{'skip_packages'} and builtin::reftype($self->{'skip_packages'}) eq 'REGEXP') { } 6 9 15
31 $self->{send_msg} = sub {
32 1 ▶ my $text = shift || '';
Subroutine __ANON__: called CC=3 SCAR=11.7
Condition50%1/2
shift() || ''
l!l
10
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
33 1 ▶ $text .= "\n" unless $text =~ /\n$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\n$/ 1 0 1
34 1 warn $text;
35 1 };
36 }
37 ▶ elsif ( $self->{skip_packages}
Condition100%3/3
$self->{"skip_packages"} and builtin::reftype($self->{"skip_packages"}) eq "REGEXP"
!ll&&!rl&&r
636
MC/DC100%2/2
$self->{"skip_packages"} and builtin::reftype($self->{"skip_packages"}) eq "REGEXP"
$self->{"skip_packages"} builtin::reftype($self->{"skip_packages"}) eq "REGEXP"
Truth table100%3/3
A and B
A= $self->{"skip_packages"}B= builtin::reftype($self->{"skip_packages"}) eq "REGEXP"
ABresult
0X0
100
111
38 and reftype( $self->{skip_packages} ) eq 'REGEXP' )
39 {
40 my $skipadd = '|^Log::Any::|^Carp::Clan::'
41 6 ▶ . ( $self->{skip_me} ? "|^$callpack\$" : '' );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'skip_me'} ? : 0 6 6
42 6 my $skipre = qr/$self->{skip_packages}$skipadd/;
43  
44 6 require Carp::Clan;
45 {
46  
47 6 package Log::Any::Adapter::Carp::Clannish;
48 6 Carp::Clan->import($skipre);
49 }
50 3 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
51 $self->{send_msg} =
52 $self->{full_trace}
53 6 ▶ ? *Log::Any::Adapter::Carp::Clannish::cluck
Branch: 1 branch
BranchTrueFalseTotal
$self->{'full_trace'} ? : 3 3 6
54 : *Log::Any::Adapter::Carp::Clannish::carp;
55 }
56 else {
57 9 require Carp;
58 {
59  
60 9 package Log::Any::Adapter::Carp::Carpish;
61 9 Carp->import(qw/ carp cluck /);
62 }
63  
64 9 my @skip_pkgs;
65 push @skip_pkgs, $callpack
66 9 ▶ if $self->{skip_me};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"skip_me"} 1 8 9
67  
68 9 ▶ if ( exists $self->{skip_packages} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"skip_packages"}) 3 6 9
69 3 ▶ if ( reftype $self->{skip_packages} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($self->{'skip_packages'}) eq 'ARRAY') { } 1 2 3
70 1 push @skip_pkgs, @{ $self->{skip_packages} };
71 }
72 else {
73 2 push @skip_pkgs, $self->{skip_packages};
74 }
75 }
76  
77 my $carp =
78 $self->{full_trace}
79 9 ▶ ? *Log::Any::Adapter::Carp::Carpish::cluck
Branch: 1 branch
BranchTrueFalseTotal
$self->{'full_trace'} ? : 3 6 9
80 : *Log::Any::Adapter::Carp::Carpish::carp;
81  
82 $self->{send_msg} = sub {
83  
84 # Ugh, but this is the only Carp mechanism to keep a package out
85 # of the shortmess if the call is *from* it
86 7 ▶ local %Carp::Internal;
Subroutine __ANON__: called CC=2 SCAR=6.9
87 7 $Carp::Internal{$_}++ for @skip_pkgs;
88 7 $carp->(@_);
89 }
90 9 }
91  
92 }
93  
94 3 foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) {
95 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
96 27 my $method_level = Log::Any::Adapter::Util::numeric_level($method);
97 27 *{$method} = sub {
98 11 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
99 11 ▶ return if $method_level > $self->{log_level};
Branch: 1 branch
BranchTrueFalseTotal
if $method_level > $self->{"log_level"} 1 10 11
100 10 $self->{send_msg}->(@_);
101 27 };
102 }
103  
104 3 foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) {
105 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
106 27 my $base = substr( $method, 3 );
107 27 my $method_level = Log::Any::Adapter::Util::numeric_level($base);
108 27 *{$method} = sub {
109 20 ▶ return !!( $method_level <= $_[0]->{log_level} );
Subroutine __ANON__: called CC=1 SCAR=0.0
110 27 };
111 }
112  
113 3 1;
114  
115 __END__
↑ Summary Build »