lib/Mail/Decency/Policy/Core/CWLCBL.pm

filter: Statementstmt 40.0% 18 / 45 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 50.0% 3 / 6 Podpod 100% 3 / 3 totaltotal 26.0% 24 / 92 CC 15 SCAR 37.0
CC
15
Cov
24%
handle
72.0
cache_and_state
30.0
init
20.0
CRAP 40.5
« lib/Mail/Decency/Helper/Logger.pm ↑ Summary lib/Mail/Decency/LogParser/GeoSource.pm »
1 package Mail::Decency::Policy::Core::CWLCBL;
2  
3  
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 extends qw/
6 Mail::Decency::Policy::Core
7 /;
8 1 with qw/
9 Mail::Decency::Core::Meta::Database
10 /;
11  
12 1 ▶use version 0.74; our $VERSION = qv( "v0.1.4" );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =head1 NAME
17  
18 Mail::Decency::Policy::Core::CWLCBL
19  
20 =head1 DESCRIPTION
21  
22 Base class for CWL and CBL. Don't use directly.
23  
24 =cut
25  
26 1 has _handle_on_hit => ( is => 'ro', isa => 'Str' );
27 1 has _table_prefix => ( is => 'ro', isa => 'Str' );
28 1 has _use_weight => ( is => 'ro', isa => 'Bool' );
29 1 has _description => ( is => 'ro', isa => 'Str' );
30 1 has use_tables => ( is => 'rw', isa => 'HashRef[Int]' );
31  
32  
33 =head1 METHODS
34  
35 =head2 init
36  
37 Read config, init tables.
38  
39 =cut
40  
41 0 ▶sub init {
Subroutine init: not called CC=4 SCAR=30.0
Pod documented
42 0 my ( $self ) = @_;
43
44 0 my %tables_ok = map { ( $_ => 1 ) } qw/ ips domains addresses /;
45 my @tables = defined $self->config->{ tables }
46 0 ▶ ? @{ $self->config->{ tables } }
Branch: 1 branch
BranchTrueFalseTotal
defined $self->config->{'tables'} ? : 0 0 0
47 : keys %tables_ok
48 ;
49 0 foreach my $table( @tables ) {
50 die "Cannot use table '$table', please use only ". join( ", ", sort keys %tables_ok ). "\n"
51 0 ▶ unless $tables_ok{ $table }
Branch: 1 branch
BranchTrueFalseTotal
unless $tables_ok{$table} 0 0 0
52 }
53
54 # set tables
55 0 $self->use_tables( { map { ( $_ => 1 ) } @tables } );
56  
57 }
58  
59  
60 =head2 handle
61  
62 Handle method for CWL or CBL.
63  
64 =cut
65  
66 0 ▶sub handle {
Subroutine handle: not called CC=8 SCAR=42.8
Pod documented
67 0 my ( $self, $server, $attrs_ref ) = @_;
68
69 # is answer in cache ?
70 0 my $cache_name = $self->name. "-". $self->cache->hash_to_name( $attrs_ref, qw/
71 sender_address
72 recipient_address
73 client_address
74 / );
75 0 ▶ if ( defined( my $cached = $self->cache->get( $cache_name ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $cached = $self->cache->get($cache_name))) 0 0 0
76 0 $self->cache_and_state( $cache_name, @$cached, $attrs_ref );
77 }
78
79 # check wheter ip/hostname
80 0 ▶ if ( $self->use_tables->{ ips } && ( my $ips_ref = $self->database->get( $self->_table_prefix => ips => {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_tables->{"ips"} and my $ips_ref = $self->database->get($self->_table_prefix, "ips", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "client_address", $attrs_ref->{"client_address"}})) 0 0 0
Condition0%0/3
$self->use_tables->{"ips"} and my $ips_ref = $self->database->get($self->_table_prefix, "ips", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "client_address", $attrs_ref->{"client_address"}})
!ll&&!rl&&r
000
MC/DC0%0/2
$self->use_tables->{"ips"} and my $ips_ref = $self->database->get($self->_table_prefix, "ips", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "client_address", $attrs_ref->{"client_address"}})
$self->use_tables->{"ips"} my $ips_ref = $self->database->get($self->_table_prefix, "ips", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "client_address", $attrs_ref->{"client_address"}})
Truth table0%0/3
A and B
A= $self->use_tables->{"ips"}B= my $ips_ref = $self->database->get($self->_table_prefix, "ips", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "client_address", $attrs_ref->{"client_address"}})
ABresult
0X0
100
111
81 recipient_domain => $attrs_ref->{ recipient_domain },
82 client_address => $attrs_ref->{ client_address }
83 } ) ) ) {
84 0 $self->cache_and_state( $cache_name => $self->_handle_on_hit, "ip", $attrs_ref );
85 }
86
87 # look in domain databsae
88 0 ▶ if ( $self->use_tables->{ domains } && ( my $domains_ref = $self->database->get( $self->_table_prefix => domains => {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_tables->{"domains"} and my $domains_ref = $self->database->get($self->_table_prefix, "domains", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "sender_domain", $attrs_ref->{"sender_domain"}})) 0 0 0
Condition0%0/3
$self->use_tables->{"domains"} and my $domains_ref = $self->database->get($self->_table_prefix, "domains", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "sender_domain", $attrs_ref->{"sender_domain"}})
!ll&&!rl&&r
000
MC/DC0%0/2
$self->use_tables->{"domains"} and my $domains_ref = $self->database->get($self->_table_prefix, "domains", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "sender_domain", $attrs_ref->{"sender_domain"}})
$self->use_tables->{"domains"} my $domains_ref = $self->database->get($self->_table_prefix, "domains", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "sender_domain", $attrs_ref->{"sender_domain"}})
Truth table0%0/3
A and B
A= $self->use_tables->{"domains"}B= my $domains_ref = $self->database->get($self->_table_prefix, "domains", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "sender_domain", $attrs_ref->{"sender_domain"}})
ABresult
0X0
100
111
89 recipient_domain => $attrs_ref->{ recipient_domain },
90 sender_domain => $attrs_ref->{ sender_domain }
91 } ) ) ) {
92 0 $self->cache_and_state( $cache_name => $self->_handle_on_hit, "domain", $attrs_ref );
93 }
94
95 # look in address databse
96 0 ▶ if ( $self->use_tables->{ addresses } && ( my $address_ref = $self->database->get( $self->_table_prefix => addresses => {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_tables->{"addresses"} and my $address_ref = $self->database->get($self->_table_prefix, "addresses", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "sender_address", $attrs_ref->{"sender_address"}})) 0 0 0
Condition0%0/3
$self->use_tables->{"addresses"} and my $address_ref = $self->database->get($self->_table_prefix, "addresses", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "sender_address", $attrs_ref->{"sender_address"}})
!ll&&!rl&&r
000
MC/DC0%0/2
$self->use_tables->{"addresses"} and my $address_ref = $self->database->get($self->_table_prefix, "addresses", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "sender_address", $attrs_ref->{"sender_address"}})
$self->use_tables->{"addresses"} my $address_ref = $self->database->get($self->_table_prefix, "addresses", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "sender_address", $attrs_ref->{"sender_address"}})
Truth table0%0/3
A and B
A= $self->use_tables->{"addresses"}B= my $address_ref = $self->database->get($self->_table_prefix, "addresses", {"recipient_domain", $attrs_ref->{"recipient_domain"}, "sender_address", $attrs_ref->{"sender_address"}})
ABresult
0X0
100
111
97 recipient_domain => $attrs_ref->{ recipient_domain },
98 sender_address => $attrs_ref->{ sender_address }
99 } ) ) ) {
100 0 $self->cache_and_state( $cache_name => $self->_handle_on_hit, "address", $attrs_ref );
101 }
102
103
104 # remember cached, if negative ok ..
105 0 $self->cache_and_state( $cache_name => 'DUNNO', "nohit", $attrs_ref );
106
107 0 return ;
108 }
109  
110 =head2 cache_and_state
111  
112 Do cache and call go_finale_state
113  
114 =cut
115  
116 0 ▶sub cache_and_state {
Subroutine cache_and_state: not called CC=5 SCAR=34.0
Pod documented
117 0 my ( $self, $cache_name, $state, $where, $attrs_ref ) = @_;
118
119 0 my $final = $state ne 'DUNNO';
120
121 # save back to cache
122 0 ▶ if ( $final || $self->config->{ use_negative_cache } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final or $self->config->{"use_negative_cache"}) 0 0 0
Condition0%0/3
$final or $self->config->{"use_negative_cache"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$final or $self->config->{"use_negative_cache"}
$final $self->config->{"use_negative_cache"}
Truth table0%0/3
A or B
A= $finalB= $self->config->{"use_negative_cache"}
ABresult
1X1
011
000
123 0 $self->cache->set( $cache_name => [ $state, $where ] );
124 }
125
126 0 ▶ $self->logger->debug0( "Got hit in $where: '$attrs_ref->{ sender_address }' -> '$attrs_ref->{ recipient_address }': $state" )
Branch: 1 branch
BranchTrueFalseTotal
if $final 0 0 0
127 if $final;
128
129 # set final state ..
130 0 ▶ $self->go_final_state( $state, "Hit on ". $self->_description ) if $final;
Branch: 1 branch
BranchTrueFalseTotal
if $final 0 0 0
131 }
132  
133 =head1 AUTHOR
134  
135 Ulrich Kautz <uk@fortrabbit.de>
136  
137 =head1 COPYRIGHT
138  
139 Copyright (c) 2010 the L</AUTHOR> as listed above
140  
141 =head1 LICENCSE
142  
143 This library is free software and may be distributed under the same terms as perl itself.
144  
145 =cut
146  
147  
148 1 1;
« lib/Mail/Decency/Helper/Logger.pm ↑ Summary lib/Mail/Decency/LogParser/GeoSource.pm »