blib/lib/MojoX/Log/Fast.pm

filter: Statementstmt 26.0% 12 / 46 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 25.0% 3 / 12 Podpod 100% 8 / 8 totaltotal 24.2% 23 / 95 CC 11 SCAR 27.7
CC
11
Cov
17%
level
30.0
_message
30.0
new
12.0
CRAP 16.0
↑ Summary
1 package MojoX::Log::Fast;
2  
3 2 ▶use Mojo::Base 'Mojo::Log';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = 'v1.2.0';
7  
8 2 ▶use Log::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 2 my %MapLevel = (
12 debug => 'DEBUG',
13 info => 'INFO',
14 warn => 'WARN',
15 error => 'ERR',
16 fatal => 'ERR',
17 );
18  
19  
20 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
21 0 my $self = shift->SUPER::new();
22 0 ▶ $self->{'_logger'} = shift || Log::Fast->global();
Condition0%0/3
shift() || 'Log::Fast'->global
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || 'Log::Fast'->global
shift() 'Log::Fast'->global
Truth table0%0/3
A || B
A= shift()B= 'Log::Fast'->global
ABresult
1X1
011
000
23 0 ▶ if ($ENV{MOJO_LOG_LEVEL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'MOJO_LOG_LEVEL'}) { } 0 0 0
24 0 $self->level($ENV{MOJO_LOG_LEVEL});
25 }
26 else {
27 0 $self->level({reverse %MapLevel}->{ $self->{_logger}->level });
28 }
29 0 $self->unsubscribe('message');
30 0 $self->on(message => \&_message);
31 0 return $self;
32 }
33  
34 0 ▶sub context {
Subroutine context: not called CC=1 SCAR=6.9
Pod documented
35 0 my ($parent, @context) = @_;
36 0 my $self = $parent->new();
37 0 $self->level($parent->level);
38 0 $self->{'context'} = \@context;
39 0 return $self;
40 }
41  
42 0 ▶sub config { return shift->{'_logger'}->config(@_); }
Subroutine config: not called CC=1 SCAR=6.9
Pod documented
43 0 ▶sub ident { return shift->{'_logger'}->ident(@_); }
Subroutine ident: not called CC=1 SCAR=6.9
Pod documented
44  
45 0 ▶sub handle { croak q{log->handle: not supported, use log->config} };
Subroutine handle: not called CC=1 SCAR=6.9
Pod documented
46 0 ▶sub path { croak q{log->path: not supported, use log->config} };
Subroutine path: not called CC=1 SCAR=6.9
Pod documented
47 0 ▶sub format { croak q{log->format: not implemented} }; ## no critic(ProhibitBuiltinHomonyms)
Subroutine format: not called CC=1 SCAR=6.9
Pod documented
48  
49 0 ▶sub level {
Subroutine level: not called CC=5 SCAR=34.0
Pod documented
50 0 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
51 0 ▶ return $_[0]{'level'} if exists $_[0]{'level'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_[0]{"level"} 0 0 0
52 0 return $_[0]{'level'} = 'debug';
53 }
54 0 ▶ $_[0]{'level'} = $ENV{MOJO_LOG_LEVEL} || $_[1];
Condition0%0/3
$ENV{'MOJO_LOG_LEVEL'} || $_[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'MOJO_LOG_LEVEL'} || $_[1]
$ENV{'MOJO_LOG_LEVEL'} $_[1]
Truth table0%0/3
A || B
A= $ENV{'MOJO_LOG_LEVEL'}B= $_[1]
ABresult
1X1
011
000
55 0 ▶ $_[0]{'_logger'}->level($MapLevel{ $ENV{MOJO_LOG_LEVEL} || $_[1] });
Condition0%0/3
$ENV{'MOJO_LOG_LEVEL'} || $_[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'MOJO_LOG_LEVEL'} || $_[1]
$ENV{'MOJO_LOG_LEVEL'} $_[1]
Truth table0%0/3
A || B
A= $ENV{'MOJO_LOG_LEVEL'}B= $_[1]
ABresult
1X1
011
000
56 0 return $_[0];
57 }
58  
59 0 ▶sub _message {
Subroutine _message: not called CC=5 SCAR=34.0
60 0 my ($self, $level, @lines) = @_;
61 0 ▶ if ($self->{'context'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"context"}) 0 0 0
62 0 unshift @lines, @{$self->{context}}
63 }
64 0 ▶ if ($level eq 'debug') {
Branch: 3 branches
BranchTrueFalseTotal
if ($level eq 'debug') { } 0 0 0
elsif ($level eq 'info') { } 0 0 0
elsif ($level eq 'warn') { } 0 0 0
65 0 $self->{'_logger'}->DEBUG(join q{ }, @lines);
66 } elsif ($level eq 'info') {
67 0 $self->{'_logger'}->INFO(join q{ }, @lines);
68 } elsif ($level eq 'warn') {
69 0 $self->{'_logger'}->WARN(join q{ }, @lines);
70 } else { # error, fatal
71 0 $self->{'_logger'}->ERR(join q{ }, @lines);
72 }
73 0 return;
74 }
75  
76 2 1; # Magic true value required at end of module
77 __END__
↑ Summary