| 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
| |||||||||||||||||||||
| 11 | 2 | ▶ | $self->{Streams} ||= [ $class->_streams() ]; | ||||||||||||||||||
|
Condition50%1/2
$self->{"Streams"} ||= [$class->_streams]
MC/DC0%0/1
$self->{"Streams"} ||= [$class->_streams]
$self->{"Streams"}
Truth table50%1/2
A
A= $self->{"Streams"}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 38 | 29 | ▶ | /^\@/ and $self->handle_fancy($_), next GETLINE; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 29 | ▶ | /^\$/ and $self->handle_dollar($_), next GETLINE; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 23 | ▶ | /^\:/ and $self->handle_colon($_), next GETLINE; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 21 | ▶ | s/^!// and $self->{is_exclusion} = 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 21 | ▶ | /\S/ or next GETLINE; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 21 | ▶ | warn ("returning Record: identity=$identity; value=$value; additional=$additional; stream=$stream\n") if $self->debug; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 21 | ▶ | return new Mail::Karmasphere::Parser::Record | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 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'}
MC/DC50%1/2
$txt || $self->{'default'}{'txt'}
$txt
$self->{'default'}{'txt'}
Truth table66%2/3
A || B
A= $txtB= $self->{'default'}{'txt'}
| |||||||||||||||||||||
| 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'}
MC/DC0%0/2
shift() || $self->{'default'}{'a'}
shift()
$self->{'default'}{'a'}
Truth table33%1/3
A || B
A= shift()B= $self->{'default'}{'a'}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | # exclusions are operated as whitelists | ||||||||||||||||||||
| 89 | 21 | ▶ | return - $value if $self->{is_exclusion}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 103 | 2 | ▶ | $self->{default}->{txt} = $default_txt if $default_txt; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 3 | 1; | |||||||||||||||||||