Amazon/S3/Logger.pm

filter: Statementstmt 98.0% 51 / 52 Branchbran 70.0% 7 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 2 totaltotal 84.7% 72 / 85 CC 8 SCAR 11.2
CC
8
Cov
88%
_log_message
6.9
new
2.0
level
2.0
CRAP 3.1
« Amazon/S3/Util.pm ↑ Summary Digest/CRC64NVME.pm »
1 package Amazon::S3::Logger;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use Amazon::S3::Constants qw{ :chars };
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 ▶use English qw{-no_match_vars};
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use Scalar::Util qw{ reftype };
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 12 our $VERSION = '2.1.4'; ## no critic (RequireInterpolationOfMetachars)
14  
15 12 Readonly::Hash our %LOG_LEVELS => (
16 trace => 5,
17 debug => 4,
18 info => 3,
19 warn => 2,
20 error => 1,
21 fatal => 0,
22 );
23  
24 {
25 12 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 12 foreach my $level (qw{fatal error warn info debug trace}) {
28  
29 72 ▶ *{ __PACKAGE__ . $DOUBLE_COLON . $level } = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
30 174 my ( $self, @message ) = @_;
31 174 $self->_log_message( $level, @message );
32 72 };
33 }
34 }
35  
36 ########################################################################
37 24 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
38 ########################################################################
39 24 my ( $class, @args ) = @_;
40  
41 24 ▶ my $options = ref $args[0] ? $args[0] : {@args};
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] ? : 0 24 24
42  
43 24 return bless $options, $class;
44 }
45  
46 ########################################################################
47 23 ▶sub level {
Subroutine level: called CC=2 SCAR=6.9
Pod undocumented
48 ########################################################################
49 23 my ( $self, @args ) = @_;
50  
51 23 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 6 17 23
52 6 $self->{log_level} = $args[0];
53 }
54  
55 23 return $self->{log_level};
56 }
57  
58 ########################################################################
59 174 ▶sub _log_message {
Subroutine _log_message: called CC=6 SCAR=19.3
60 ########################################################################
61 174 my ( $self, $level, @message ) = @_;
62  
63 174 ▶ return if $LOG_LEVELS{ lc $level } > $LOG_LEVELS{ lc $self->{log_level} };
Branch: 1 branch
BranchTrueFalseTotal
if $Amazon::S3::Logger::LOG_LEVELS{lc $level} > $Amazon::S3::Logger::LOG_LEVELS{lc $self->{"log_level"}} 138 36 174
64 36 ▶ return if !@message;
Branch: 1 branch
BranchTrueFalseTotal
unless @message 0 36 36
65  
66 36 my $log_message;
67  
68 36 ▶ if ( defined $message[0]
Branch: 1 branch
BranchTrueFalseTotal
if (defined $message[0] and ref $message[0] and builtin::reftype($message[0]) eq 'CODE') { } 0 36 36
Condition33%2/6
defined $message[0] and ref $message[0] and builtin::reftype($message[0]) eq "CODE"
!ll&&!rl&&r
3600
defined $message[0] and ref $message[0]
!ll&&!rl&&r
0360
MC/DC0%0/3
defined $message[0] and ref $message[0] and builtin::reftype($message[0]) eq "CODE"
defined $message[0] ref $message[0] builtin::reftype($message[0]) eq "CODE"
Truth table25%1/4
A and B and C
A= defined $message[0]B= ref $message[0]C= builtin::reftype($message[0]) eq "CODE"
ABCresult
0XX0
10X0
1100
1111
69 && ref $message[0]
70 && reftype( $message[0] ) eq 'CODE' ) {
71 0 $log_message = $message[0]->();
72 }
73 else {
74 36 $log_message = join $EMPTY, @message;
75 }
76  
77 36 chomp $log_message;
78  
79 36 my @tm = localtime time;
80  
81 36 my $timestamp = POSIX::strftime '%Y/%m/%d %H:%M:%S', @tm;
82  
83 36 return print {*STDERR} sprintf qq{%s: %s %s %s\n}, uc $level, $timestamp, $PROCESS_ID, $log_message;
84 }
85  
86 12 1;
« Amazon/S3/Util.pm ↑ Summary Digest/CRC64NVME.pm »