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