blib/lib/DTL/Fast/Filter/Timesince.pm

filter: Statementstmt 100% 46 / 46 Branchbran 87.5% 7 / 8 Conditioncond 55.5% 5 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 84.4% 65 / 77 SCAR 23.1
CC
10
Cov
92%
time_diff
9.5
parse_parameters
2.0
BEGIN
1.0
CRAP 10.0
« blib/lib/DTL/Fast/Tag/Ssi.pm ↑ Summary blib/lib/DTL/Fast/Filter/Ru/Pluralize.pm »
1 package DTL::Fast::Filter::Timesince;
2 3 ▶use strict; use utf8; use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use parent 'DTL::Fast::Filter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 $DTL::Fast::FILTER_HANDLERS{'timesince'} = __PACKAGE__;
6  
7 3 our $MAXSTEPS = 2;
8  
9 3 our @LAPSE = (
10 ['minute', 60]
11 );
12  
13 3 unshift @LAPSE, ['hour', $LAPSE[0]->[1] * 60];
14 3 unshift @LAPSE, ['day', $LAPSE[0]->[1] * 24];
15 3 unshift @LAPSE, ['week', $LAPSE[0]->[1] * 7];
16 3 unshift @LAPSE, ['month', $LAPSE[1]->[1] * 30];
17 3 unshift @LAPSE, ['year', $LAPSE[2]->[1] * 365];
18  
19  
20 #@Override
21 #@todo make pre-defined formats from Django
22 sub parse_parameters
23 {
24 44 ▶ my $self = shift;
Subroutine parse_parameters: called CC=2 SCAR=6.9
Pod undocumented
25 22 push @{$self->{'parameter'}}, DTL::Fast::Variable->new(time)
26 44 ▶ if not scalar @{$self->{'parameter'}};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$self->{"parameter"};} 22 22 44
27 44 $self->{'time'} = $self->{'parameter'}->[0];
28 44 $self->{'suffix'} = DTL::Fast::Variable->new('s'); # this is pluralize related
29
30 44 return $self;
31 }
32  
33 #@Override
34 sub filter
35 {
36 44 ▶ my $self = shift; # self
Subroutine filter: called CC=1 SCAR=0.0
Pod undocumented
37 44 shift; # filter_manager
38 44 my $value = shift;
39 44 my $context = shift;
40
41 44 my $time = $self->{'time'}->render($context);
42
43 44 return $self->time_diff($time - $value);
44 }
45  
46 sub time_diff
47 {
48 44 ▶ my $self = shift;
Subroutine time_diff: called CC=9 SCAR=22.5
Pod undocumented
49 44 my $diff = shift;
50 44 my @diffs = ();
51
52 44 ▶ if( $diff )
Branch: 1 branch
BranchTrueFalseTotal
if ($diff) 44 0 44
53 {
54 44 foreach my $lapse (@LAPSE)
55 {
56 236 ▶ if( $diff >= $lapse->[1] )
Branch: 1 branch
BranchTrueFalseTotal
if ($diff >= $lapse->[1]) 64 172 236
57 {
58 64 my $val = int( $diff / $lapse->[1]);
59 64 $diff = $diff % $lapse->[1];
60 push @diffs, sprintf( '%d %s%s'
61 , $val // 'undef'
62 , $lapse->[0] // 'undef'
63 64 ▶ , ($DTL::Fast::FILTER_HANDLERS{'pluralize'} // require DTL::Fast::Filter::Pluralize && 'DTL::Fast::Filter::Pluralize')->pluralize($val, ['s'])
Condition55%5/9
$val // "undef"
l!l
640
$lapse->[0] // "undef"
l!l
640
$DTL::Fast::FILTER_HANDLERS{"pluralize"} // require DTL::Fast::Filter::Pluralize && "DTL::Fast::Filter::Pluralize"
l!l&&r!l&&!r
6220
require DTL::Fast::Filter::Pluralize and "DTL::Fast::Filter::Pluralize"
!ll
02
MC/DC0%0/1
$val // "undef"
$val
MC/DC0%0/1
$lapse->[0] // "undef"
$lapse->[0]
MC/DC0%0/2
$DTL::Fast::FILTER_HANDLERS{"pluralize"} // require DTL::Fast::Filter::Pluralize && "DTL::Fast::Filter::Pluralize"
$DTL::Fast::FILTER_HANDLERS{"pluralize"} require DTL::Fast::Filter::Pluralize
Truth table50%1/2
A
A= $val
Aresult
11
00
Truth table50%1/2
A
A= $lapse->[0]
Aresult
11
00
Truth table66%2/3
A // B
A= $DTL::Fast::FILTER_HANDLERS{"pluralize"}B= require DTL::Fast::Filter::Pluralize
ABresult
1X1
011
000
64 );
65
66 64 ▶ if( scalar @diffs == $MAXSTEPS )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @diffs == $DTL::Fast::Filter::Timesince::MAXSTEPS) 24 40 64
67 {
68 24 last;
69 }
70 }
71 }
72 }
73  
74 44 return join ', ', @diffs;
75 }
76  
77 3 1;
« blib/lib/DTL/Fast/Tag/Ssi.pm ↑ Summary blib/lib/DTL/Fast/Filter/Ru/Pluralize.pm »