API/Logger.pm

filter: Statementstmt 96.5% 28 / 29 Branchbran 87.5% 7 / 8 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 82.4% 47 / 57 SCAR 21.0
CC
8
Cov
87%
AUTOLOAD
7.6
new
2.0
BEGIN
1.0
CRAP 8.2
« API/Request.pm ↑ Summary Constants.pm »
1 package Binance::API::Logger;
2  
3 # MIT License
4 #
5 # Copyright (c) 2017 Lari Taskula <lari@taskula.fi>
6 #
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be included in all
15 # copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 # SOFTWARE.
24  
25 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 3 ▶use Binance::Constants qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 =head1 NAME
33  
34 Binance::API::Logger -- Logger for L<Binance::API>
35  
36 =head1 DESCRIPTION
37  
38 Provides a wrapper for your desired logger. Carps log calls higher than "debug"
39 level
40  
41 =head1 SYNOPSIS
42  
43 use Binance::API;
44  
45 my $logger = Binance::API::Logger->new($log4perl);
46  
47 $logger->warn("This is a warning");
48  
49 =head1 METHODS
50  
51 =cut
52  
53 =head2 new
54  
55 my $logger = Binance::API::Logger->new($log4perl);
56  
57 Instantiates a new C<Binance::API::Logger> object.
58  
59 B<PARAMETERS>
60  
61 =over
62  
63 =item A logger object that implements (at least) debug, warn,
64 error, fatal level logging.
65  
66 [OPTIONAL]
67  
68 =back
69  
70 B<RETURNS>
71  
72 A C<Binance::API::Logger> object.
73  
74 =cut
75  
76 sub new {
77 5 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
78  
79 5 my $self = {
80 logger => undef,
81 };
82  
83 5 ▶ $self->{logger} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 2 5
84  
85 5 bless $self, $class;
86 }
87  
88 sub AUTOLOAD {
89 56 ▶ my $self = shift;
Subroutine AUTOLOAD: called CC=7 SCAR=20.3
90  
91 56 my $level = our $AUTOLOAD;
92 56 $level =~ s/.*://;
93  
94 56 ▶ return if $level eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $level eq "DESTROY" 5 51 56
95  
96 51 ▶ my $message = shift || "";
Condition50%1/2
shift() || ''
l!l
510
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
97  
98 51 my $sub = (caller(1))[3];
99 51 my $full_message = "[$sub] ". $message;
100  
101 51 ▶ if ($level eq 'debug' || $level eq 'trace') {
Branch: 1 branch
BranchTrueFalseTotal
if ($level eq 'debug' or $level eq 'trace') { } 14 37 51
Condition66%2/3
$level eq "debug" or $level eq "trace"
l!l&&r!l&&!r
14037
MC/DC50%1/2
$level eq "debug" or $level eq "trace"
$level eq "debug" $level eq "trace"
Truth table66%2/3
A or B
A= $level eq "debug"B= $level eq "trace"
ABresult
1X1
011
000
102 14 carp $full_message if DEBUG;
103 } else {
104 37 carp $full_message;
105 }
106  
107 51 ▶ if ($self->{logger} && $self->{logger}->can($level)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"} and $self->{"logger"}->can($level)) 0 51 51
Condition33%1/3
$self->{"logger"} and $self->{"logger"}->can($level)
!ll&&!rl&&r
5100
MC/DC0%0/2
$self->{"logger"} and $self->{"logger"}->can($level)
$self->{"logger"} $self->{"logger"}->can($level)
Truth table33%1/3
A and B
A= $self->{"logger"}B= $self->{"logger"}->can($level)
ABresult
0X0
100
111
108 0 $self->{logger}->$level($full_message);
109 }
110 }
111  
112 3 1;
« API/Request.pm ↑ Summary Constants.pm »