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

filter: Statementstmt 100% 33 / 33 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 93.8% 46 / 49 SCAR 17.9
CC
6
Cov
98%
filter
5.0
parse_parameters
2.0
BEGIN
1.0
CRAP 6.0
« blib/lib/DTL/Fast/Tag/If.pm ↑ Summary blib/lib/DTL/Fast/Filter/Divisibleby.pm »
1 package DTL::Fast::Filter::Truncatewords;
2 3 ▶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 3 ▶use parent 'DTL::Fast::Filter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 $DTL::Fast::FILTER_HANDLERS{'truncatewords'} = __PACKAGE__;
6  
7 #@Override
8 sub parse_parameters
9 {
10 4 ▶ my $self = shift;
Subroutine parse_parameters: called CC=2 SCAR=7.0
Pod undocumented
11 die $self->get_parse_error("no max words number specified")
12 4 ▶ if not scalar @{$self->{'parameter'}};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$self->{"parameter"};} 0 4 4
13 4 $self->{'maxlen'} = $self->{'parameter'}->[0];
14 4 return $self;
15 }
16  
17 #@Override
18 sub filter
19 {
20 4 ▶ my($self, $filter_manager, $value, $context ) = @_;
Subroutine filter: called CC=5 SCAR=16.1
Pod undocumented
21
22 4 my $maxlen = $self->{'maxlen'}->render($context);
23 4 my @value = split /(\s+)/s, $value;
24 4 my $words = 0;
25 4 my @newvalue = ();
26
27 4 foreach my $value (@value)
28 {
29 35 ▶ if( $words == $maxlen )
Branch: 1 branch
BranchTrueFalseTotal
if ($words == $maxlen) { } 2 33 35
30 {
31 2 last;
32 }
33 else
34 {
35 33 push @newvalue, $value;
36 33 ▶ if( $value !~ /^\s+$/s )
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /^\s+$/s) 18 15 33
37 {
38 18 $words++;
39 }
40 }
41 }
42  
43 4 ▶ if( scalar @newvalue < scalar @value )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @newvalue < scalar @value) 2 2 4
44 {
45 2 push @newvalue, '...';
46 }
47
48 4 return join '', @newvalue;
49 }
50  
51  
52 3 1;
« blib/lib/DTL/Fast/Tag/If.pm ↑ Summary blib/lib/DTL/Fast/Filter/Divisibleby.pm »