| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DTL::Fast::Filter::Wordwrap; |
|
2
|
2
|
|
|
2
|
|
921
|
use strict; use utf8; use warnings FATAL => 'all'; |
|
|
2
|
|
|
2
|
|
3
|
|
|
|
2
|
|
|
2
|
|
56
|
|
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
11
|
|
|
|
2
|
|
|
|
|
50
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
75
|
|
|
3
|
2
|
|
|
2
|
|
7
|
use parent 'DTL::Fast::Filter'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$DTL::Fast::FILTER_HANDLERS{'wordwrap'} = __PACKAGE__; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#@Override |
|
8
|
|
|
|
|
|
|
sub parse_parameters |
|
9
|
|
|
|
|
|
|
{ |
|
10
|
4
|
|
|
4
|
0
|
3
|
my $self = shift; |
|
11
|
|
|
|
|
|
|
die $self->get_parse_error("no wrapping width specified") |
|
12
|
4
|
50
|
|
|
|
4
|
if not scalar @{$self->{'parameter'}}; |
|
|
4
|
|
|
|
|
8
|
|
|
13
|
4
|
|
|
|
|
5
|
$self->{'maxwidth'} = $self->{'parameter'}->[0]; |
|
14
|
4
|
|
|
|
|
10
|
return $self; |
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#@Override |
|
19
|
|
|
|
|
|
|
sub filter |
|
20
|
|
|
|
|
|
|
{ |
|
21
|
4
|
|
|
4
|
0
|
4
|
my($self, $filter_manager, $value, $context ) = @_; |
|
22
|
|
|
|
|
|
|
|
|
23
|
4
|
|
|
|
|
9
|
my $maxwidth = $self->{'maxwidth'}->render($context); |
|
24
|
4
|
|
|
|
|
28
|
my @value = split /\s+/s, $value; |
|
25
|
4
|
|
|
|
|
4
|
my @result = (); |
|
26
|
4
|
|
|
|
|
4
|
my $width = 0; |
|
27
|
|
|
|
|
|
|
|
|
28
|
4
|
|
|
|
|
5
|
foreach my $value (@value) |
|
29
|
|
|
|
|
|
|
{ |
|
30
|
31
|
|
|
|
|
15
|
my $length = length $value; |
|
31
|
31
|
100
|
|
|
|
44
|
if( $width == 0 ) |
|
|
|
100
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
{ |
|
33
|
4
|
|
|
|
|
7
|
push @result, $value; |
|
34
|
4
|
|
|
|
|
8
|
$width += $length; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
elsif( $length + $width + 1 > $maxwidth ) |
|
37
|
|
|
|
|
|
|
{ |
|
38
|
15
|
|
|
|
|
15
|
push @result, "\n", $value; |
|
39
|
15
|
|
|
|
|
11
|
$width = $length; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
else |
|
42
|
|
|
|
|
|
|
{ |
|
43
|
12
|
|
|
|
|
8
|
push @result, ' ', $value; |
|
44
|
12
|
|
|
|
|
13
|
$width += $length + 1; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
4
|
|
|
|
|
18
|
return join '', @result; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |