line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Filter::Truncatewords; |
2
|
3
|
|
|
3
|
|
1107
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
69
|
|
3
|
3
|
|
|
3
|
|
13
|
use utf8; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
24
|
|
4
|
3
|
|
|
3
|
|
60
|
use warnings FATAL => 'all'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
93
|
|
5
|
3
|
|
|
3
|
|
13
|
use parent 'DTL::Fast::Filter'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
19
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$DTL::Fast::FILTER_HANDLERS{truncatewords} = __PACKAGE__; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#@Override |
10
|
|
|
|
|
|
|
sub parse_parameters |
11
|
|
|
|
|
|
|
{ |
12
|
4
|
|
|
4
|
0
|
7
|
my $self = shift; |
13
|
|
|
|
|
|
|
die $self->get_parse_error("no max words number specified") |
14
|
4
|
50
|
|
|
|
5
|
if (not scalar @{$self->{parameter}}); |
|
4
|
|
|
|
|
13
|
|
15
|
4
|
|
|
|
|
7
|
$self->{maxlen} = $self->{parameter}->[0]; |
16
|
4
|
|
|
|
|
12
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#@Override |
20
|
|
|
|
|
|
|
sub filter |
21
|
|
|
|
|
|
|
{ |
22
|
4
|
|
|
4
|
0
|
11
|
my ($self, $filter_manager, $value, $context ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
|
|
17
|
my $maxlen = $self->{maxlen}->render($context); |
25
|
4
|
|
|
|
|
32
|
my @value = split /(\s+)/s, $value; |
26
|
4
|
|
|
|
|
10
|
my $words = 0; |
27
|
4
|
|
|
|
|
27
|
my @newvalue = (); |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
|
|
10
|
foreach my $value (@value) |
30
|
|
|
|
|
|
|
{ |
31
|
35
|
100
|
|
|
|
66
|
if ($words == $maxlen) |
32
|
|
|
|
|
|
|
{ |
33
|
2
|
|
|
|
|
5
|
last; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else |
36
|
|
|
|
|
|
|
{ |
37
|
33
|
|
|
|
|
53
|
push @newvalue, $value; |
38
|
33
|
100
|
|
|
|
87
|
if ($value !~ /^\s+$/s) |
39
|
|
|
|
|
|
|
{ |
40
|
18
|
|
|
|
|
30
|
$words++; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
4
|
100
|
|
|
|
11
|
if (scalar @newvalue < scalar @value) |
46
|
|
|
|
|
|
|
{ |
47
|
2
|
|
|
|
|
5
|
push @newvalue, '...'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
4
|
|
|
|
|
23
|
return join '', @newvalue; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |