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

filter: Statementstmt 100% 34 / 34 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 93.7% 45 / 48 SCAR 16.1
CC
5
Cov
98%
filter
4.0
parse_parameters
2.0
BEGIN
1.0
CRAP 5.0
« blib/lib/DTL/Fast/Filter/Floatformat.pm ↑ Summary blib/lib/DTL/Fast/Tag/With.pm »
1 package DTL::Fast::Filter::Wordwrap;
2 2 ▶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 2 ▶use parent 'DTL::Fast::Filter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 $DTL::Fast::FILTER_HANDLERS{'wordwrap'} = __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 wrapping width specified")
12 4 ▶ if not scalar @{$self->{'parameter'}};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$self->{"parameter"};} 0 4 4
13 4 $self->{'maxwidth'} = $self->{'parameter'}->[0];
14 4 return $self;
15 }
16  
17  
18 #@Override
19 sub filter
20 {
21 4 ▶ my($self, $filter_manager, $value, $context ) = @_;
Subroutine filter: called CC=4 SCAR=13.9
Pod undocumented
22  
23 4 my $maxwidth = $self->{'maxwidth'}->render($context);
24 4 my @value = split /\s+/s, $value;
25 4 my @result = ();
26 4 my $width = 0;
27
28 4 foreach my $value (@value)
29 {
30 31 my $length = length $value;
31 31 ▶ if( $width == 0 )
Branch: 2 branches
BranchTrueFalseTotal
if ($width == 0) { } 4 27 31
elsif ($length + $width + 1 > $maxwidth) { } 15 12 27
32 {
33 4 push @result, $value;
34 4 $width += $length;
35 }
36 elsif( $length + $width + 1 > $maxwidth )
37 {
38 15 push @result, "\n", $value;
39 15 $width = $length;
40 }
41 else
42 {
43 12 push @result, ' ', $value;
44 12 $width += $length + 1;
45 }
46 }
47
48 4 return join '', @result;
49 }
50  
51 2 1;
« blib/lib/DTL/Fast/Filter/Floatformat.pm ↑ Summary blib/lib/DTL/Fast/Tag/With.pm »