DRI/Logging.pm

filter: Statementstmt 44.7% 43 / 96 Branchbran 23.8% 10 / 42 Conditioncond 26.4% 9 / 34 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 63.6% 7 / 11 Podpod 33.3% 2 / 6 totaltotal 33.6% 71 / 211 CC 35 SCAR 45.3
CC
35
Cov
36%
string_data
240.0
new
31.5
level
7.2
CRAP 92.5
« DRI/Protocol/EPP/Extensions/PL/Report.pm ↑ Summary DRI/Protocol/EPP/Extensions/NO/Result.pm »
1 ## Domain Registry Interface, Logging operations for Net::DRI
2 ##
3 ## Copyright (c) 2009-2010,2012 Patrick Mevzek <netdri@dotandco.com>. All rights reserved.
4 ##
5 ## This file is part of Net::DRI
6 ##
7 ## Net::DRI is free software; you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation; either version 2 of the License, or
10 ## (at your option) any later version.
11 ##
12 ## See the LICENSE file that comes with this distribution for more details.
13 ####################################################################################################
14  
15 package Net::DRI::Logging;
16  
17 79 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 79 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 79 ▶use base qw/Net::DRI::BaseClass/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 79 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 79 ▶use Net::DRI::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 79 __PACKAGE__->make_exception_if_not_implemented(qw/name setup_channel output/);
25  
26 ## Taken from Log::Log4Perl
27 79 our %LEVELS=qw/debug 0 info 1 notice 2 warning 3 error 4 critical 5 alert 6 emergency 7/;
28  
29 ####################################################################################################
30 ## Public API
31  
32 sub new
33 77 ▶{
Subroutine new: called CC=16 SCAR=34.5
Pod documented
34 77 my $c=shift;
35 77 ▶ my $self=shift || {};
Condition50%1/2
shift() || {}
l!l
077
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
36 77 ▶ if (! exists $self->{level} || ! defined $self->{level} ) { $self->{level} =3; }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"level"} and defined $self->{"level"}) 77 0 77
Condition33%1/3
exists $self->{"level"} and defined $self->{"level"}
!ll&&!rl&&r
7700
MC/DC0%0/2
exists $self->{"level"} and defined $self->{"level"}
exists $self->{"level"} defined $self->{"level"}
Truth table33%1/3
A and B
A= exists $self->{"level"}B= defined $self->{"level"}
ABresult
0X0
100
111
37 77 ▶ if (! exists $self->{xml_indent} || ! defined $self->{xml_indent} ) { $self->{xml_indent} =0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"xml_indent"} and defined $self->{"xml_indent"}) 77 0 77
Condition33%1/3
exists $self->{"xml_indent"} and defined $self->{"xml_indent"}
!ll&&!rl&&r
7700
MC/DC0%0/2
exists $self->{"xml_indent"} and defined $self->{"xml_indent"}
exists $self->{"xml_indent"} defined $self->{"xml_indent"}
Truth table33%1/3
A and B
A= exists $self->{"xml_indent"}B= defined $self->{"xml_indent"}
ABresult
0X0
100
111
38 77 ▶ if (! exists $self->{encoding} || ! defined $self->{encoding} ) { $self->{encoding} ='UTF-8'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"encoding"} and defined $self->{"encoding"}) 77 0 77
Condition33%1/3
exists $self->{"encoding"} and defined $self->{"encoding"}
!ll&&!rl&&r
7700
MC/DC0%0/2
exists $self->{"encoding"} and defined $self->{"encoding"}
exists $self->{"encoding"} defined $self->{"encoding"}
Truth table33%1/3
A and B
A= exists $self->{"encoding"}B= defined $self->{"encoding"}
ABresult
0X0
100
111
39 77 ▶ if (! exists $self->{format_header} || ! defined $self->{format_header} ) { $self->{format_header} ='%FULLTIME [%ULEVEL] <%TYPE>'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"format_header"} and defined $self->{"format_header"}) 77 0 77
Condition33%1/3
exists $self->{"format_header"} and defined $self->{"format_header"}
!ll&&!rl&&r
7700
MC/DC0%0/2
exists $self->{"format_header"} and defined $self->{"format_header"}
exists $self->{"format_header"} defined $self->{"format_header"}
Truth table33%1/3
A and B
A= exists $self->{"format_header"}B= defined $self->{"format_header"}
ABresult
0X0
100
111
40 77 ▶ if (! exists $self->{format_transport} || ! defined $self->{format_transport} ) { $self->{format_transport}='%TRID %UDIRECTION %MESSAGE'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"format_transport"} and defined $self->{"format_transport"}) 77 0 77
Condition33%1/3
exists $self->{"format_transport"} and defined $self->{"format_transport"}
!ll&&!rl&&r
7700
MC/DC0%0/2
exists $self->{"format_transport"} and defined $self->{"format_transport"}
exists $self->{"format_transport"} defined $self->{"format_transport"}
Truth table33%1/3
A and B
A= exists $self->{"format_transport"}B= defined $self->{"format_transport"}
ABresult
0X0
100
111
41 77 ▶ if (! exists $self->{format_protocol} || ! defined $self->{format_protocol} ) { $self->{format_protocol} ='%TRID %UDIRECTION %MESSAGE'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"format_protocol"} and defined $self->{"format_protocol"}) 77 0 77
Condition33%1/3
exists $self->{"format_protocol"} and defined $self->{"format_protocol"}
!ll&&!rl&&r
7700
MC/DC0%0/2
exists $self->{"format_protocol"} and defined $self->{"format_protocol"}
exists $self->{"format_protocol"} defined $self->{"format_protocol"}
Truth table33%1/3
A and B
A= exists $self->{"format_protocol"}B= defined $self->{"format_protocol"}
ABresult
0X0
100
111
42 77 ▶ if (! exists $self->{sanitize_data} || ! defined $self->{sanitize_data} ) { $self->{sanitize_data} = {}; }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"sanitize_data"} and defined $self->{"sanitize_data"}) 77 0 77
Condition33%1/3
exists $self->{"sanitize_data"} and defined $self->{"sanitize_data"}
!ll&&!rl&&r
7700
MC/DC0%0/2
exists $self->{"sanitize_data"} and defined $self->{"sanitize_data"}
exists $self->{"sanitize_data"} defined $self->{"sanitize_data"}
Truth table33%1/3
A and B
A= exists $self->{"sanitize_data"}B= defined $self->{"sanitize_data"}
ABresult
0X0
100
111
43 77 bless $self,$c;
44 77 $self->level($self->{level}); ## convert the level token to a numerical value
45 77 return $self;
46 }
47  
48 sub level
49 77 ▶{
Subroutine level: called CC=5 SCAR=19.7
Pod documented
50 77 my ($self,$level)=@_;
51 77 ▶ if (defined $level)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $level) 77 0 77
52 {
53 0 ▶ if (exists $LEVELS{$level}) { $level=$LEVELS{$level}; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Net::DRI::Logging::LEVELS{$level}) 0 77 77
54 0 ▶ if ($level!~/^\d+$/ || $level > 7) { $self->output('error','logging','Invalid level value "'.$level.'", switching to default'); $level=3; }
Branch: 1 branch
BranchTrueFalseTotal
if (not $level =~ /^\d+$/ or $level > 7) 0 77 77
Condition33%1/3
not $level =~ /^\d+$/ or $level > 7
l!l&&r!l&&!r
0077
MC/DC0%0/2
not $level =~ /^\d+$/ or $level > 7
not $level =~ /^\d+$/ $level > 7
Truth table33%1/3
not(A) or B
A= not $level =~ /^\d+$/B= $level > 7
ABresult
1X1
011
000
55 77 $self->{level}=$level;
56 }
57 77 return $self->{level};
58 }
59  
60 ####################################################################################################
61 ## Internal API
62  
63 sub string_header
64 0 ▶{
Subroutine string_header: not called CC=1 SCAR=6.9
Pod undocumented
65 0 my ($self,$level,$type,$data)=@_;
66 0 my $f=$self->{format_header};
67 0 $f=~s/%FULLTIME/Net::DRI::Util::fulltime()/eg;
68 0 $f=~s/%ULEVEL/uc($level)/eg;
69 0 $f=~s/%TYPE/$type/g;
70 0 return $f;
71 }
72  
73 sub string_data
74 0 ▶{
Subroutine string_data: not called CC=15 SCAR=54.8
Pod undocumented
75 0 my ($self,$hdr,$type,$data)=@_;
76 0 ▶ if (! ref $data || ! exists $self->{'format_'.$type}) { return $hdr.q{ }.$data; }
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data and exists $$self{'format_' . $type}) 0 0 0
Condition0%0/3
ref $data and exists $$self{'format_' . $type}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $data and exists $$self{'format_' . $type}
ref $data exists $$self{'format_' . $type}
Truth table0%0/3
A and B
A= ref $dataB= exists $$self{'format_' . $type}
ABresult
0X0
100
111
77 0 my $msg=$data->{message};
78 0 my $ct=q{};
79 0 my $ref=ref $msg;
80 0 ▶ if ($ref)
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) 0 0 0
81 {
82 0 ▶ if ($ref eq 'Net::DRI::Data::Raw')
Branch: 1 branch
BranchTrueFalseTotal
if ($ref eq 'Net::DRI::Data::Raw') { } 0 0 0
83 {
84 0 $ct=$msg->hint();
85 } else
86 {
87 0 ▶ if (! $msg->can('as_string')) { Net::DRI::Exception::method_not_implemented('as_string',ref $msg); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($msg->can("as_string")) 0 0 0
88 }
89 0 $msg=$msg->as_string($self->{sanitize_data});
90 }
91  
92 ## If this is deemed to be too brittle, a type() method could be added to Protocol/Message and correctly set to "xml" by Message classes in RRI,EPP,OpenSRS/XCP,IRIS/{XCP,LWZ}
93 0 ▶ if (! length($ct) && substr($msg,0,5) eq '<?xml') { $ct='xml'; }
Branch: 1 branch
BranchTrueFalseTotal
if (not length $ct and substr($msg, 0, 5) eq "<?xml") 0 0 0
Condition0%0/3
not length $ct and substr($msg, 0, 5) eq "<?xml"
!ll&&!rl&&r
000
MC/DC0%0/2
not length $ct and substr($msg, 0, 5) eq "<?xml"
not length $ct substr($msg, 0, 5) eq "<?xml"
Truth table0%0/3
not(A) and B
A= not length $ctB= substr($msg, 0, 5) eq "<?xml"
ABresult
0X0
100
111
94  
95 0 ▶ if ($ct eq 'xml')
Branch: 1 branch
BranchTrueFalseTotal
if ($ct eq "xml") 0 0 0
96 {
97 0 ▶ if ($self->{xml_indent})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'xml_indent'}) { } 0 0 0
98 {
99 0 $msg=Net::DRI::Util::xml_indent($msg);
100 } else
101 {
102 0 $msg=~s/^\s+//mg;
103 0 $msg=~s/\s+$//mg;
104 0 $msg=~s/\n/ /g;
105 0 $msg=~s/> </></g;
106 }
107 }
108  
109 0 ▶ $data->{all}=join q{ },map { $_.q{=}.(defined $data->{$_} ? $data->{$_} : '') } sort { $a cmp $b } keys %{$data}; ## this should be handy during debugging
Branch: 1 branch
BranchTrueFalseTotal
defined $data->{$_} ? : 0 0 0
110 0 ▶ if (exists $data->{direction}) { $data->{udirection}=uc $data->{direction}; $data->{adirection}=$data->{direction} eq 'in'? 'C<=S' : 'C=>S';}
Branch: 2 branches
BranchTrueFalseTotal
if (exists $data->{"direction"}) 0 0 0
$data->{'direction'} eq 'in' ? : 0 0 0
111 0 my @r;
112 0 foreach my $l (split /\n/,$msg)
113 {
114 0 my $f=$hdr.q{ }.$self->{'format_'.$type};
115 0 $data->{message}=$l;
116 0 ▶ $f=~s/%([A-Z]+)/$data->{lc $1} || ''/eg;
Condition0%0/2
$$data{lc $1} || ''
l!l
00
MC/DC0%0/1
$$data{lc $1} || ''
$$data{lc $1}
Truth table0%0/2
A
A= $$data{lc $1}
Aresult
11
00
117 0 push @r,$f;
118 }
119 0 return join qq{\n}, @r;
120 }
121  
122 sub tostring
123 0 ▶{
Subroutine tostring: not called CC=1 SCAR=6.9
Pod undocumented
124 0 my ($self,$level,$type,$data)=@_;
125 0 my $hdr=$self->string_header($level,$type);
126 0 my $r=$self->string_data($hdr,$type,$data);
127 0 return Net::DRI::Util::encode($self->{encoding},$r);
128 }
129  
130 sub should_log
131 0 ▶{
Subroutine should_log: not called CC=2 SCAR=17.9
Pod undocumented
132 0 my ($self,$level)=@_;
133 0 ▶ return ($LEVELS{$level} >= $self->{level})? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$Net::DRI::Logging::LEVELS{$level} >= $self->{'level'} ? : 0 0 0
134 }
135  
136 ####################################################################################################
137 79 1;
138  
139 __END__
« DRI/Protocol/EPP/Extensions/PL/Report.pm ↑ Summary DRI/Protocol/EPP/Extensions/NO/Result.pm »