line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Filter::Truncatechars; |
2
|
3
|
|
|
3
|
|
1154
|
use strict; use utf8; use warnings FATAL => 'all'; |
|
3
|
|
|
3
|
|
4
|
|
|
3
|
|
|
3
|
|
65
|
|
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
52
|
|
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
109
|
|
3
|
3
|
|
|
3
|
|
8
|
use parent 'DTL::Fast::Filter'; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
13
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$DTL::Fast::FILTER_HANDLERS{'truncatechars'} = __PACKAGE__; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#@Override |
8
|
|
|
|
|
|
|
sub parse_parameters |
9
|
|
|
|
|
|
|
{ |
10
|
8
|
|
|
8
|
0
|
8
|
my $self = shift; |
11
|
|
|
|
|
|
|
die $self->get_parse_error("no max string length specified") |
12
|
8
|
50
|
|
|
|
6
|
if not scalar @{$self->{'parameter'}}; |
|
8
|
|
|
|
|
15
|
|
13
|
8
|
|
|
|
|
10
|
$self->{'maxlen'} = $self->{'parameter'}->[0]; |
14
|
8
|
|
|
|
|
17
|
return $self; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#@Override |
18
|
|
|
|
|
|
|
sub filter |
19
|
|
|
|
|
|
|
{ |
20
|
8
|
|
|
8
|
0
|
11
|
my($self, $filter_manager, $value, $context ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
8
|
|
|
|
|
18
|
my $maxlen = $self->{'maxlen'}->render($context); |
23
|
8
|
50
|
|
|
|
22
|
if( length $value > $maxlen ) |
24
|
|
|
|
|
|
|
{ |
25
|
8
|
|
|
|
|
13
|
$value = substr $value, 0, $maxlen; |
26
|
8
|
|
|
|
|
36
|
$value =~ s/\s*$/.../s; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
8
|
|
|
|
|
20
|
return $value; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |