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