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

filter: Statementstmt 100% 25 / 25 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 89.1% 33 / 37 SCAR 11.0
CC
3
Cov
93%
parse_parameters
2.0
filter
2.0
BEGIN
1.0
CRAP 3.0
« blib/lib/DTL/Fast/Tag/Sprintf.pm ↑ Summary blib/lib/DTL/Fast/Expression/Operator/Binary/And.pm »
1 package DTL::Fast::Filter::Truncatechars;
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{'truncatechars'} = __PACKAGE__;
6  
7 #@Override
8 sub parse_parameters
9 {
10 8 ▶ my $self = shift;
Subroutine parse_parameters: called CC=2 SCAR=7.0
Pod undocumented
11 die $self->get_parse_error("no max string length specified")
12 8 ▶ if not scalar @{$self->{'parameter'}};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$self->{"parameter"};} 0 8 8
13 8 $self->{'maxlen'} = $self->{'parameter'}->[0];
14 8 return $self;
15 }
16  
17 #@Override
18 sub filter
19 {
20 8 ▶ my($self, $filter_manager, $value, $context ) = @_;
Subroutine filter: called CC=2 SCAR=7.0
Pod undocumented
21
22 8 my $maxlen = $self->{'maxlen'}->render($context);
23 8 ▶ if( length $value > $maxlen )
Branch: 1 branch
BranchTrueFalseTotal
if (length $value > $maxlen) 8 0 8
24 {
25 8 $value = substr $value, 0, $maxlen;
26 8 $value =~ s/\s*$/.../s;
27 }
28
29 8 return $value;
30 }
31  
32  
33 3 1;
« blib/lib/DTL/Fast/Tag/Sprintf.pm ↑ Summary blib/lib/DTL/Fast/Expression/Operator/Binary/And.pm »