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