Karmasphere/Parser/RBL/Base.pm

filter: Statementstmt 93.1% 54 / 58 Branchbran 71.8% 23 / 32 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 76.9% 10 / 13 Podpod 0.0% 0 / 7 totaltotal 74.8% 92 / 123 CC 20 SCAR 18.2
CC
20
Cov
83%
_parse
12.3
a_to_value
4.2
new
3.1
CRAP 6.2
« Karmasphere/Parser/Record.pm ↑ Summary Karmasphere/Parser/Simple/List.pm »
1 package Mail::Karmasphere::Parser::RBL::Base;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use base 'Mail::Karmasphere::Parser::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Mail::Karmasphere::Parser::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶sub new {
Subroutine new: called CC=3 SCAR=11.4
Pod undocumented
9 2 my $class = shift;
10 0 ▶ my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
$#_ == 0 ? : 0 2 2
11 2 ▶ $self->{Streams} ||= [ $class->_streams() ];
Condition50%1/2
$self->{"Streams"} ||= [$class->_streams]
l!l
02
MC/DC0%0/1
$self->{"Streams"} ||= [$class->_streams]
$self->{"Streams"}
Truth table50%1/2
A
A= $self->{"Streams"}
Aresult
11
00
12 2 $self = $class->SUPER::new($self);
13 2 $self->{default}->{a} = "127.0.0.2";
14 2 $self->{default}->{txt} = undef;
15 2 return $self;
16 }
17  
18 0 ▶sub _streams { die "subclass of RBL::Base must define _streams()" }
Subroutine _streams: not called CC=1 SCAR=6.9
19  
20 0 ▶sub my_format { die "subclass of RBL::Base must define my_format()" }
Subroutine my_format: not called CC=1 SCAR=6.9
Pod undocumented
21  
22 23 ▶sub _parse {
Subroutine _parse: called CC=12 SCAR=25.1
23 23 my $self = shift;
24  
25 GETLINE:
26 23 ▶ while ( not eof($self->fh)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $self->fh) 44 2 46
27 44 local $_ = $self->fh->getline;
28  
29 44 my $additional;
30 my $value; #[ -1000 .. 1000 ]
31  
32 # XXX This should be an argument to a_to_value, or
33 # it should be handled in this routine. It should NOT
34 # be an instance variable.
35 44 $self->{is_exclusion} = 0;
36
37 44 ▶ /^\#/ and next GETLINE;
Branch: 1 branch
BranchTrueFalseTotal
/^\#/ and next GETLINE 15 29 44
38 29 ▶ /^\@/ and $self->handle_fancy($_), next GETLINE;
Branch: 1 branch
BranchTrueFalseTotal
/^\@/ and $self->handle_fancy($_), next GETLINE 0 29 29
39 29 ▶ /^\$/ and $self->handle_dollar($_), next GETLINE;
Branch: 1 branch
BranchTrueFalseTotal
/^\$/ and $self->handle_dollar($_), next GETLINE 6 23 29
40 23 ▶ /^\:/ and $self->handle_colon($_), next GETLINE;
Branch: 1 branch
BranchTrueFalseTotal
/^\:/ and $self->handle_colon($_), next GETLINE 2 21 23
41 21 ▶ s/^!// and $self->{is_exclusion} = 1;
Branch: 1 branch
BranchTrueFalseTotal
s/^!// and $self->{"is_exclusion"} = 1 1 20 21
42 21 ▶ /\S/ or next GETLINE;
Branch: 1 branch
BranchTrueFalseTotal
/\S/ or next GETLINE 21 0 21
43  
44 21 chomp;
45 21 my @F = split /\s*:\s*/;
46  
47 21 $value = $self->a_to_value($F[1]);
48 21 $additional = $self->txt_to_additional($F[2]);
49
50 21 ▶ my ($type, $stream, $identity) = $self->tweaks(@F) or next GETLINE;
Branch: 1 branch
BranchTrueFalseTotal
() = $self->tweaks(@F) or next GETLINE 21 0 21
51  
52 21 ▶ warn ("returning Record: identity=$identity; value=$value; additional=$additional; stream=$stream\n") if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 21 21
53  
54 21 ▶ return new Mail::Karmasphere::Parser::Record
Branch: 2 branches
BranchTrueFalseTotal
defined $additional ? : 9 12 21
defined $type ? : 21 0 21
55 (
56 s => $stream,
57 i => $identity,
58 v => $value,
59 (defined $additional ? (d => $additional) : ()), # this is what elsewhere thinks of as "data".
60 (defined $type ? (t => $type) : ()),
61 );
62 }
63  
64 2 return;
65 }
66  
67  
68 # ----------------------------------------------------------
69 # functions
70 # ----------------------------------------------------------
71  
72 21 ▶sub txt_to_additional {
Subroutine txt_to_additional: called CC=2 SCAR=7.0
Pod undocumented
73 21 my $self = shift;
74 21 my $txt = shift;
75 21 ▶ return $txt || $self->{default}->{txt};
Condition66%2/3
$txt || $self->{'default'}{'txt'}
l!l&&r!l&&!r
0912
MC/DC50%1/2
$txt || $self->{'default'}{'txt'}
$txt $self->{'default'}{'txt'}
Truth table66%2/3
A || B
A= $txtB= $self->{'default'}{'txt'}
ABresult
1X1
011
000
76 }
77  
78 21 ▶sub a_to_value {
Subroutine a_to_value: called CC=4 SCAR=14.5
Pod undocumented
79 21 my $self = shift;
80 21 ▶ my $a = shift || $self->{default}->{a};
Condition33%1/3
shift() || $self->{'default'}{'a'}
l!l&&r!l&&!r
0210
MC/DC0%0/2
shift() || $self->{'default'}{'a'}
shift() $self->{'default'}{'a'}
Truth table33%1/3
A || B
A= shift()B= $self->{'default'}{'a'}
ABresult
1X1
011
000
81  
82 # if 127.0.0.2 means "black"
83 # and 127.0.0.4 means "white",
84 # this is where we would put the logic to return the appropriate value.
85  
86 21 ▶ my $value = defined $self->{Value} ? $self->{Value} : 1000;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'Value'} ? : 21 0 21
87  
88 # exclusions are operated as whitelists
89 21 ▶ return - $value if $self->{is_exclusion};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_exclusion"} 1 20 21
90  
91 20 return $value;
92 }
93  
94 0 ▶sub handle_fancy { my $self = shift; }
Subroutine handle_fancy: not called CC=1 SCAR=6.9
Pod undocumented
95 6 ▶sub handle_dollar { my $self = shift; }
Subroutine handle_dollar: called CC=1 SCAR=0.0
Pod undocumented
96  
97 2 ▶sub handle_colon {
Subroutine handle_colon: called CC=3 SCAR=11.2
Pod undocumented
98 2 my $self = shift;
99 2 my $line = shift;
100 2 chomp $line;
101 2 my ($null, $default_a, $default_txt) = split /:/, $line, 3;
102 2 ▶ $self->{default}->{a} = $default_a if $default_a;
Branch: 1 branch
BranchTrueFalseTotal
if $default_a 2 0 2
103 2 ▶ $self->{default}->{txt} = $default_txt if $default_txt;
Branch: 1 branch
BranchTrueFalseTotal
if $default_txt 2 0 2
104 }
105  
106 3 1;
« Karmasphere/Parser/Record.pm ↑ Summary Karmasphere/Parser/Simple/List.pm »