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