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