| 1 | package DTL::Fast::Filter::Truncatechars; | ||||||||||
| 2 | 3 | ▶ | use strict; use utf8; use warnings FATAL => 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use parent 'DTL::Fast::Filter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 3 | $DTL::Fast::FILTER_HANDLERS{'truncatechars'} = __PACKAGE__; | |||||||||
| 6 | |||||||||||
| 7 | #@Override | ||||||||||
| 8 | sub parse_parameters | ||||||||||
| 9 | { | ||||||||||
| 10 | 8 | ▶ | my $self = shift; | ||||||||
|
Subroutine
parse_parameters: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 11 | die $self->get_parse_error("no max string length specified") | ||||||||||
| 12 | 8 | ▶ | if not scalar @{$self->{'parameter'}}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 8 | $self->{'maxlen'} = $self->{'parameter'}->[0]; | |||||||||
| 14 | 8 | return $self; | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | #@Override | ||||||||||
| 18 | sub filter | ||||||||||
| 19 | { | ||||||||||
| 20 | 8 | ▶ | my($self, $filter_manager, $value, $context ) = @_; | ||||||||
|
Subroutine
filter: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 21 | |||||||||||
| 22 | 8 | my $maxlen = $self->{'maxlen'}->render($context); | |||||||||
| 23 | 8 | ▶ | if( length $value > $maxlen ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | { | ||||||||||
| 25 | 8 | $value = substr $value, 0, $maxlen; | |||||||||
| 26 | 8 | $value =~ s/\s*$/.../s; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 8 | return $value; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | 3 | 1; | |||||||||