line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Filter::Pluralize; |
2
|
5
|
|
|
5
|
|
1141
|
use strict; use utf8; use warnings FATAL => 'all'; |
|
5
|
|
|
5
|
|
7
|
|
|
5
|
|
|
5
|
|
126
|
|
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
103
|
|
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
173
|
|
3
|
5
|
|
|
5
|
|
17
|
use parent 'DTL::Fast::Filter'; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
24
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$DTL::Fast::FILTER_HANDLERS{'pluralize'} = __PACKAGE__; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#@Override |
8
|
|
|
|
|
|
|
sub parse_parameters |
9
|
|
|
|
|
|
|
{ |
10
|
5
|
|
|
5
|
0
|
4
|
my $self = shift; |
11
|
2
|
|
|
|
|
16
|
push @{$self->{'parameter'}}, DTL::Fast::Variable->new('"s"') |
12
|
5
|
100
|
|
|
|
6
|
if not scalar @{$self->{'parameter'}}; |
|
5
|
|
|
|
|
9
|
|
13
|
5
|
|
|
|
|
7
|
$self->{'suffix'} = $self->{'parameter'}->[0]; |
14
|
5
|
|
|
|
|
8
|
return $self; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#@Override |
18
|
|
|
|
|
|
|
#@todo this method should be locale-specific |
19
|
|
|
|
|
|
|
sub filter |
20
|
|
|
|
|
|
|
{ |
21
|
16
|
|
|
16
|
0
|
14
|
my $self = shift; # self |
22
|
16
|
|
|
|
|
8
|
shift; # filter_manager |
23
|
16
|
|
|
|
|
14
|
my $value = shift; |
24
|
16
|
|
|
|
|
14
|
my $context = shift; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
return $self->pluralize($value, [ |
27
|
16
|
|
|
|
|
33
|
split /\s*,\s*/, $self->{'suffix'}->render($context) |
28
|
|
|
|
|
|
|
]); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub pluralize |
32
|
|
|
|
|
|
|
{ |
33
|
69
|
|
|
69
|
0
|
61
|
my $self = shift; |
34
|
69
|
|
50
|
|
|
98
|
my $value = shift // 0; |
35
|
69
|
|
|
|
|
45
|
my $suffix = shift; |
36
|
|
|
|
|
|
|
|
37
|
69
|
100
|
|
|
|
97
|
my $suffix_one = scalar @$suffix > 1 ? |
38
|
|
|
|
|
|
|
shift @$suffix |
39
|
|
|
|
|
|
|
: ''; |
40
|
|
|
|
|
|
|
|
41
|
69
|
|
|
|
|
59
|
my $suffix_more = shift @$suffix; |
42
|
|
|
|
|
|
|
|
43
|
69
|
100
|
|
|
|
122
|
if( $value != 1 ) |
44
|
|
|
|
|
|
|
{ |
45
|
31
|
|
|
|
|
33
|
$value = $suffix_more; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else |
48
|
|
|
|
|
|
|
{ |
49
|
38
|
|
|
|
|
40
|
$value = $suffix_one; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
69
|
|
|
|
|
237
|
return $value; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |