| 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
| |||||||||||
| 11 | 1 | my $type = $self->{Type}; | |||||||||
| 12 | 1 | ▶ | unless ($type) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 1 | $type = lc $class; | |||||||||
| 14 | 1 | $type =~ s/.*:://; | |||||||||
| 15 | } | ||||||||||
| 16 | 1 | ▶ | $self->{Streams} = [ $type ] unless $self->{Streams}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 24 | 4 | ▶ | return 1000 unless $text =~ /\S/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 33 | 10 | ▶ | next if $line =~ /^#/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 5 | ▶ | next unless $line =~ /\S/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 5 | chomp($line); | |||||||||
| 36 | 5 | my $csv = new Text::CSV(); | |||||||||
| 37 | 5 | ▶ | unless ($csv->parse($line)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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; | |||||||||