Karmasphere/Parser/Score/Base.pm

filter: Statementstmt 92.5% 37 / 40 Branchbran 66.6% 12 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 84.8% 56 / 66 CC 10 SCAR 12.6
CC
10
Cov
84%
_parse
5.3
new
4.2
_value
3.0
CRAP 3.5
« Karmasphere/Parser/Simple/List.pm ↑ Summary Karmasphere/Parser/RBL/Mixed.pm »
1 package Mail::Karmasphere::Parser::Score::Base;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base 'Mail::Karmasphere::Parser::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Text::CSV;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶sub new {
Subroutine new: called CC=4 SCAR=14.5
Pod undocumented
9 1 my $class = shift;
10 0 ▶ my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
$#_ == 0 ? : 0 1 1
11 1 my $type = $self->{Type};
12 1 ▶ unless ($type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 1 0 1
13 1 $type = lc $class;
14 1 $type =~ s/.*:://;
15 }
16 1 ▶ $self->{Streams} = [ $type ] unless $self->{Streams};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Streams"} 1 0 1
17 1 $self = $class->SUPER::new($self);
18 1 return $self;
19 }
20  
21 5 ▶sub _value {
Subroutine _value: called CC=3 SCAR=11.0
22 5 my $text = shift;
23 5 ▶ return 1000 unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 1 4 5
24 4 ▶ return 1000 unless $text =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\S/ 1 3 4
25 3 return 0+ $text;
26 }
27  
28 5 ▶sub _parse {
Subroutine _parse: called CC=5 SCAR=16.7
29 5 my $self = shift;
30 5 LINE: for (;;) {
31 10 my $line = $self->fh->getline;
32 10 ▶ return undef unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 10 10
33 10 ▶ next if $line =~ /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#/ 5 5 10
34 5 ▶ next unless $line =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/ 0 5 5
35 5 chomp($line);
36 5 my $csv = new Text::CSV();
37 5 ▶ unless ($csv->parse($line)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($csv->parse($line)) 0 5 5
38 0 warn "Failed to parse CSV line $line";
39 0 next LINE;
40 }
41 5 my @fields = $csv->fields();
42 # guess_identity_type does validation, and
43 # the wrapper checks that the record type matches
44 # the stream type, so no further validation is required
45 # here. XXX It would be faster to fix the type here from
46 # $type, and do a single regex to check it.
47 5 return new Mail::Karmasphere::Parser::Record(
48 s => 0,
49 i => $fields[0],
50 v => _value($fields[1]),
51 d => $fields[2],
52 );
53 }
54 }
55  
56 2 1;
« Karmasphere/Parser/Simple/List.pm ↑ Summary Karmasphere/Parser/RBL/Mixed.pm »