Commando/Logger.pm

filter: Statementstmt 74.4% 32 / 43 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod 0.0% 0 / 7 totaltotal 63.3% 45 / 71 CC 5 SCAR 8.5
CC
5
Cov
71%
_store
5.2
BUILD
3.1
info
2.0
CRAP 2.3
« Commando/Option.pm ↑ Summary Commando/Presenter.pm »
1 package App::Commando::Logger;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Scalar::Util qw(openhandle);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 has 'device' => ( is => 'ro' );
11 9 has 'formatter' => ( is => 'rw' );
12 9 has 'level' => ( is => 'rw' );
13  
14 13 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=1 SCAR=0.0
Pod undocumented
15 13 my ($class, $device) = @_;
16  
17 return {
18 13 device => $device,
19 };
20 }
21  
22 13 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.2
Pod undocumented
23 13 my ($self) = @_;
24  
25 13 eval {
26 13 $self->{_fh} = openhandle($self->device);
27 13 ▶ open($self->{_fh}, '>>', $self->device) if !defined $self->{_fh};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_fh"} 1 12 13
28 };
29 13 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 13 13
30 0 croak 'Can\'t open log device';
31 }
32  
33 13 return $self;
34 }
35  
36 9 my %levels = (
37 'debug' => 1,
38 'info' => 2,
39 'warn' => 3,
40 'error' => 4,
41 'fatal' => 5,
42 );
43  
44 11 ▶sub _store {
Subroutine _store: called CC=3 SCAR=16.5
45 11 my ($self, $level, $message) = @_;
46  
47 11 ▶ if ($levels{lc $level} >= $levels{lc $self->{level}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($levels{lc $level} >= $levels{lc $self->{"level"}}) 0 11 11
48 0 ▶ print { $self->{_fh} }
Branch: 1 branch
BranchTrueFalseTotal
ref $self->formatter eq 'CODE' ? : 0 0 0
49 ref($self->formatter) eq 'CODE' ?
50 $self->formatter->($level, $message) : $message;
51 }
52 }
53  
54 11 ▶sub debug {
Subroutine debug: called CC=1 SCAR=0.0
Pod undocumented
55 11 my ($self, $message) = @_;
56  
57 11 $self->_store('debug', $message);
58 }
59  
60 0 ▶sub info {
Subroutine info: not called CC=1 SCAR=6.9
Pod undocumented
61 0 my ($self, $message) = @_;
62  
63 0 $self->_store('info', $message);
64 }
65  
66 0 ▶sub warn {
Subroutine warn: not called CC=1 SCAR=6.9
Pod undocumented
67 0 my ($self, $message) = @_;
68  
69 0 $self->_store('warn', $message);
70 }
71  
72 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
73 0 my ($self, $message) = @_;
74  
75 0 $self->_store('error', $message);
76 }
77  
78 0 ▶sub fatal {
Subroutine fatal: not called CC=1 SCAR=6.9
Pod undocumented
79 0 my ($self, $message) = @_;
80  
81 0 $self->_store('fatal', $message);
82 }
83  
84 9 1;
85  
86 __END__
« Commando/Option.pm ↑ Summary Commando/Presenter.pm »