lib/Mail/Decency/LogParser/Stats.pm

filter: Statementstmt 29.4% 15 / 51 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 2 totaltotal 15.7% 18 / 114 CC 22 SCAR 55.6
CC
22
Cov
16%
handle_data
380.0
setup
20.0
_cumulate
2.0
CRAP 260.9
« lib/Mail/Decency/Core/POEForking/SMTP.pm ↑ Summary lib/Mail/Decency/Policy/Basic.pm »
1 package Mail::Decency::LogParser::Stats;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 extends qw/
5 Mail::Decency::LogParser::Core
6 /;
7 1 with qw/
8 Mail::Decency::LogParser::Core::CSV
9 Mail::Decency::LogParser::Core::CacheWrite
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::LogParser::Stats
19  
20  
21 =head1 DESCRIPTION
22  
23 Generates usage statistics by configurable granulity (
24  
25 =head1 CLASS ATTRIBUTES
26  
27 =cut
28  
29 0 ▶has intervals => ( is => 'rw', isa => 'ArrayRef[Int]', default => sub { [] } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
30 1 has use_date_interval => ( is => 'rw', isa => 'Bool' );
31  
32 =head1 METHODS
33  
34  
35 =head2 init
36  
37 =cut
38  
39 0 ▶sub setup {
Subroutine setup: not called CC=4 SCAR=30.0
Pod undocumented
40 0 my ( $self ) = @_;
41
42 # setup interval caches
43 0 ▶ if ( defined $self->config->{ intervals } && ref( $self->config->{ intervals } ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->config->{'intervals'} and ref $self->config->{'intervals'} eq 'ARRAY') { } 0 0 0
Condition0%0/3
defined $self->config->{"intervals"} and ref $self->config->{"intervals"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->config->{"intervals"} and ref $self->config->{"intervals"} eq "ARRAY"
defined $self->config->{"intervals"} ref $self->config->{"intervals"} eq "ARRAY"
Truth table0%0/3
A and B
A= defined $self->config->{"intervals"}B= ref $self->config->{"intervals"} eq "ARRAY"
ABresult
0X0
100
111
44 0 $self->intervals( $self->config->{ intervals } );
45 }
46 else {
47 0 $self->intervals( [ 600, 86400 ] );
48 }
49
50 0 $self->cache_prefix( 'lp-stats' );
51
52 # wheter use date caches
53 0 ▶ $self->use_date_interval( $self->config->{ use_date_interval } ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$self->config->{'use_date_interval'} ? : 0 0 0
54 }
55  
56  
57 =head2 handle
58  
59 Checks wheter incoming mail is whilist for final recipient
60  
61 =cut
62  
63 0 ▶sub handle_data {
Subroutine handle_data: not called CC=19 SCAR=59.4
Pod undocumented
64 0 my ( $self, $parsed_ref ) = @_;
65 0 my ( %data );
66
67
68 #
69 # CONNECTIONS
70 #
71
72 0 ▶ if ( defined $parsed_ref->{ connection } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $parsed_ref->{'connection'}) { } 0 0 0
elsif ($parsed_ref->{'reject'} or $parsed_ref->{'bounced'} or $parsed_ref->{'sent'} or $parsed_ref->{'deferred'}) { } 0 0 0
73 0 ▶ my $type = $parsed_ref->{ connection } ? 'connect' : 'disconnect';
Branch: 1 branch
BranchTrueFalseTotal
$parsed_ref->{'connection'} ? : 0 0 0
74 0 ▶ push @{ $data{ connections } ||= [] }, [ $type, $parsed_ref->{ ip } ];
Condition0%0/2
$data{"connections"} ||= []
l!l
00
MC/DC0%0/1
$data{"connections"} ||= []
$data{"connections"}
Truth table0%0/2
A
A= $data{"connections"}
Aresult
11
00
75 }
76
77 ▶ elsif ( $parsed_ref->{ reject } || $parsed_ref->{ bounced } || $parsed_ref->{ sent } || $parsed_ref->{ deferred } ) {
Condition0%0/9
$parsed_ref->{"reject"} or $parsed_ref->{"bounced"} or $parsed_ref->{"sent"} or $parsed_ref->{"deferred"}
l!l&&r!l&&!r
000
$parsed_ref->{"reject"} or $parsed_ref->{"bounced"} or $parsed_ref->{"sent"}
l!l&&r!l&&!r
000
$parsed_ref->{"reject"} or $parsed_ref->{"bounced"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$parsed_ref->{"reject"} or $parsed_ref->{"bounced"} or $parsed_ref->{"sent"} or $parsed_ref->{"deferred"}
$parsed_ref->{"reject"} $parsed_ref->{"bounced"} $parsed_ref->{"sent"} $parsed_ref->{"deferred"}
Truth table0%0/5
A or B or C or D
A= $parsed_ref->{"reject"}B= $parsed_ref->{"bounced"}C= $parsed_ref->{"sent"}D= $parsed_ref->{"deferred"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
78
79 0 my %db = map { ( $_ => $parsed_ref->{ $_ } ) }
80 0 grep { defined $parsed_ref->{ $_ } }
81 qw/ ip from_address to_address from_domain to_domain /
82 ;
83
84 0 my @types;
85
86
87 #
88 # REJECTIONS
89 #
90
91 0 ▶ if ( $parsed_ref->{ reject } ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($parsed_ref->{'reject'}) { } 0 0 0
elsif ($parsed_ref->{'bounced'}) { } 0 0 0
elsif ($parsed_ref->{'deferred'}) { } 0 0 0
elsif ($parsed_ref->{'final'}) { } 0 0 0
92 0 @types = qw/ total_reject /;
93
94 0 ▶ if ( index( $parsed_ref->{ code }, '4' ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($parsed_ref->{'code'}, '4') == 0) { } 0 0 0
95 0 push @types, qw/ temp_reject /;
96 }
97 else {
98 0 push @types, qw/ hard_reject /;
99 }
100
101 0 $db{ code } = $parsed_ref->{ code };
102 0 $db{ message } = $parsed_ref->{ message };
103 }
104
105
106 #
107 # BOUNCED MAIL
108 #
109
110 elsif ( $parsed_ref->{ bounced } ) {
111 0 @types = qw/ total bounced /;
112 }
113
114
115 #
116 # BOUNCED MAIL
117 #
118
119 elsif ( $parsed_ref->{ deferred } ) {
120 0 push @types, 'deferred';
121 }
122
123
124 #
125 # FINAL
126 #
127
128 elsif ( $parsed_ref->{ final } ) {
129 0 @types = qw/ total /;
130 0 ▶ push @types, 'sent' if $parsed_ref->{ sent };
Branch: 1 branch
BranchTrueFalseTotal
if $parsed_ref->{"sent"} 0 0 0
131 }
132
133
134 0 ▶ if ( $parsed_ref->{ final } || $parsed_ref->{ bounced } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parsed_ref->{"final"} or $parsed_ref->{"bounced"}) 0 0 0
Condition0%0/3
$parsed_ref->{"final"} or $parsed_ref->{"bounced"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$parsed_ref->{"final"} or $parsed_ref->{"bounced"}
$parsed_ref->{"final"} $parsed_ref->{"bounced"}
Truth table0%0/3
A or B
A= $parsed_ref->{"final"}B= $parsed_ref->{"bounced"}
ABresult
1X1
011
000
135 0 $self->_cumulate( \%db );
136 }
137
138
139 0 ▶ if ( @types ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@types) 0 0 0
140
141 # by ip, sender-email and sender domain
142 0 foreach my $type( @types ) {
143 0 $data{ $type } = \%db;
144 }
145 }
146 }
147
148 0 ▶ return unless keys %data;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %data 0 0 0
149
150 0 $self->current_data( \%data );
151 }
152  
153  
154 =head2 _cumulate
155  
156 =cut
157  
158 0 ▶sub _cumulate {
Subroutine _cumulate: not called CC=1 SCAR=6.9
159 0 my ( $self, $db_ref ) = @_;
160
161 }
162  
163  
164  
165  
166  
167  
168  
169 =head1 AUTHOR
170  
171 Ulrich Kautz <uk@fortrabbit.de>
172  
173 =head1 COPYRIGHT
174  
175 Copyright (c) 2010 the L</AUTHOR> as listed above
176  
177 =head1 LICENCSE
178  
179 This library is free software and may be distributed under the same terms as perl itself.
180  
181 =cut
182  
183 1 1;
« lib/Mail/Decency/Core/POEForking/SMTP.pm ↑ Summary lib/Mail/Decency/Policy/Basic.pm »