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