| 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
| |||||||||||||
| 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
MC/DC0%0/1
shift() // 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 35 | 69 | my $suffix = shift; | |||||||||||
| 36 | |||||||||||||
| 37 | 69 | ▶ | my $suffix_one = scalar @$suffix > 1 ? | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | shift @$suffix | ||||||||||||
| 39 | : ''; | ||||||||||||
| 40 | |||||||||||||
| 41 | 69 | my $suffix_more = shift @$suffix; | |||||||||||
| 42 | |||||||||||||
| 43 | 69 | ▶ | if( $value != 1 ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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; | |||||||||||