lib/Mail/Decency/LogParser/Core/CacheWrite.pm

filter: Statementstmt 30.2% 13 / 43 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 60.0% 3 / 5 Podpod n/a totaltotal 29.0% 16 / 55 CC 7 SCAR 28.4
CC
7
Cov
27%
__ANON__
30.0
_update_data
12.0
BEGIN
1.0
CRAP 17.2
« lib/Mail/Decency/Core/POEForking.pm ↑ Summary lib/Mail/Decency/Helper/Database/MongoDB.pm »
1 package Mail::Decency::LogParser::Core::CacheWrite;
2  
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use version 0.74; our $VERSION = qv( "v0.1.4" );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Mail::Decency::LogParser::Core::CacheWrite
12  
13  
14 =head1 DESCRIPTION
15  
16 Logs
17  
18 =head1 CLASS ATTRIBUTES
19  
20 =cut
21  
22 1 has cache_prefix => ( is => 'rw', isa => 'Str', default => '' );
23  
24 =head1 METHODS
25  
26 =head2 handle
27  
28 =cut
29  
30 0 ▶after handle => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
31 0 my ( $self ) = @_;
32
33 0 my %data = ();
34 $data{ $_ } = $self->_update_data( $self->current_data->{ $_ } )
35 0 for keys %{ $self->current_data };
36
37 # write all caches
38 0 ▶ while( my ( $type, $data_ref ) = each %data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %data) 0 0 0
39 0 foreach my $ref( @$data_ref ) {
40 0 my $cache_name = join( "-", $self->cache_prefix, $type, @$ref );
41 #print "WRITE $cache_name\n";
42 0 ▶ my $amount = ( $self->cache->get( $cache_name ) || 0 ) + 1;
Condition0%0/2
$self->cache->get($cache_name) || 0
l!l
00
MC/DC0%0/1
$self->cache->get($cache_name) || 0
$self->cache->get($cache_name)
Truth table0%0/2
A
A= $self->cache->get($cache_name)
Aresult
11
00
43 0 $self->cache->set( $cache_name => $amount );
44 }
45 }
46 1 };
47  
48  
49 =head2 _update_data
50  
51 =cut
52  
53 0 ▶sub _update_data {
Subroutine _update_data: not called CC=3 SCAR=24.8
54 0 my ( $self, $data_ref ) = @_;
55
56 0 my @time_data = ();
57
58 # setup time based caches
59 0 my $now = time();
60
61 # setup the time intervals
62 0 ▶ if ( $self->use_date_interval ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_date_interval) 0 0 0
63
64 # get now
65 0 my @now = localtime( $now );
66 0 $now[4]++; # increment day
67
68 # caches are:
69 # * minute basis MH-<Minute>-<Hour>
70 # * hour basis HD-<Day>-<Hour>
71 # * day basis DM-<Month>-<Day>
72 0 my $min_timeout = 60 - $now[0];
73 0 my $hour_timeout = ( 60 - $now[1] ) * 60 + $min_timeout;
74 0 my $day_timeout = ( 24 - $now[2] ) * 3600 + $hour_timeout;
75 0 my @times = (
76 sprintf( 'mh-%02d-%02d', @now[1,2] ), # minute-hour-day
77 sprintf( 'hd-%02d-%02d', @now[2,3] ), # hour-day
78 sprintf( 'dm-%02d-%02d', @now[3,4] ), # day-month
79 );
80
81 push @time_data, map {
82 0 my $c = $_;
83 0 ( map { [ $c, $data_ref->{ $c }, $_ ] } @times );
84 } keys %$data_ref;
85 }
86
87 # setup interval timeouts
88 # * timeouts based on
89 0 foreach my $type( keys %$data_ref ) {
90 push @time_data, map {
91 0 my $start = $now - ( $now % $_ );
92 0 [ $type, $data_ref->{ $type }, $start + $_ ];
93 0 } @{ $self->intervals };
94 0 push @time_data, [ $type, $data_ref->{ $type }, "total" ];
95 }
96
97 0 return \@time_data;
98 }
99  
100 =head1 AUTHOR
101  
102 Ulrich Kautz <uk@fortrabbit.de>
103  
104 =head1 COPYRIGHT
105  
106 Copyright (c) 2010 the L</AUTHOR> as listed above
107  
108 =head1 LICENCSE
109  
110 This library is free software and may be distributed under the same terms as perl itself.
111  
112 =cut
113  
114 1 1;
« lib/Mail/Decency/Core/POEForking.pm ↑ Summary lib/Mail/Decency/Helper/Database/MongoDB.pm »