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