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

filter: Statementstmt 100% 34 / 34 Branchbran 100% 6 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 90.5% 48 / 53 SCAR 16.1
CC
5
Cov
98%
pluralize
4.0
parse_parameters
2.0
BEGIN
1.0
CRAP 5.0
« blib/lib/DTL/Fast/Renderer.pm ↑ Summary blib/lib/DTL/Fast/Filter/Floatformat.pm »
1 package DTL::Fast::Filter::Pluralize;
2 5 ▶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 5 ▶use parent 'DTL::Fast::Filter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 $DTL::Fast::FILTER_HANDLERS{'pluralize'} = __PACKAGE__;
6  
7 #@Override
8 sub parse_parameters
9 {
10 5 ▶ my $self = shift;
Subroutine parse_parameters: called CC=2 SCAR=6.9
Pod undocumented
11 2 push @{$self->{'parameter'}}, DTL::Fast::Variable->new('"s"')
12 5 ▶ if not scalar @{$self->{'parameter'}};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$self->{"parameter"};} 2 3 5
13 5 $self->{'suffix'} = $self->{'parameter'}->[0];
14 5 return $self;
15 }
16  
17 #@Override
18 #@todo this method should be locale-specific
19 sub filter
20 {
21 16 ▶ my $self = shift; # self
Subroutine filter: called CC=1 SCAR=0.0
Pod undocumented
22 16 shift; # filter_manager
23 16 my $value = shift;
24 16 my $context = shift;
25
26 return $self->pluralize($value, [
27 16 split /\s*,\s*/, $self->{'suffix'}->render($context)
28 ]);
29 }
30  
31 sub pluralize
32 {
33 69 ▶ my $self = shift;
Subroutine pluralize: called CC=4 SCAR=13.9
Pod undocumented
34 69 ▶ my $value = shift // 0;
Condition50%1/2
shift() // 0
l!l
690
MC/DC0%0/1
shift() // 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
35 69 my $suffix = shift;
36
37 69 ▶ my $suffix_one = scalar @$suffix > 1 ?
Branch: 1 branch
BranchTrueFalseTotal
scalar @$suffix > 1 ? : 2 67 69
38 shift @$suffix
39 : '';
40
41 69 my $suffix_more = shift @$suffix;
42
43 69 ▶ if( $value != 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($value != 1) { } 31 38 69
44 {
45 31 $value = $suffix_more;
46 }
47 else
48 {
49 38 $value = $suffix_one;
50 }
51
52 69 return $value;
53
54 }
55  
56 5 1;
« blib/lib/DTL/Fast/Renderer.pm ↑ Summary blib/lib/DTL/Fast/Filter/Floatformat.pm »