| 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
| |||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 54 | 44 | foreach my $lapse (@LAPSE) | |||||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 56 | 236 | ▶ | if( $diff >= $lapse->[1] ) | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 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"
$lapse->[0] // "undef"
$DTL::Fast::FILTER_HANDLERS{"pluralize"} // require DTL::Fast::Filter::Pluralize && "DTL::Fast::Filter::Pluralize"
require DTL::Fast::Filter::Pluralize and "DTL::Fast::Filter::Pluralize"
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
Truth table50%1/2
A
A= $lapse->[0]
Truth table66%2/3
A // B
A= $DTL::Fast::FILTER_HANDLERS{"pluralize"}B= require DTL::Fast::Filter::Pluralize
| |||||||||||||||||||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 64 | ▶ | if( scalar @diffs == $MAXSTEPS ) | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 68 | 24 | last; | |||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 44 | return join ', ', @diffs; | |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||