| 1 | package DTL::Fast::Filter::Truncatewords; | ||||||||||
| 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{'truncatewords'} = __PACKAGE__; | |||||||||
| 6 | |||||||||||
| 7 | #@Override | ||||||||||
| 8 | sub parse_parameters | ||||||||||
| 9 | { | ||||||||||
| 10 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
parse_parameters: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 11 | die $self->get_parse_error("no max words number specified") | ||||||||||
| 12 | 4 | ▶ | if not scalar @{$self->{'parameter'}}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 4 | $self->{'maxlen'} = $self->{'parameter'}->[0]; | |||||||||
| 14 | 4 | return $self; | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | #@Override | ||||||||||
| 18 | sub filter | ||||||||||
| 19 | { | ||||||||||
| 20 | 4 | ▶ | my($self, $filter_manager, $value, $context ) = @_; | ||||||||
|
Subroutine
filter: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 21 | |||||||||||
| 22 | 4 | my $maxlen = $self->{'maxlen'}->render($context); | |||||||||
| 23 | 4 | my @value = split /(\s+)/s, $value; | |||||||||
| 24 | 4 | my $words = 0; | |||||||||
| 25 | 4 | my @newvalue = (); | |||||||||
| 26 | |||||||||||
| 27 | 4 | foreach my $value (@value) | |||||||||
| 28 | { | ||||||||||
| 29 | 35 | ▶ | if( $words == $maxlen ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | { | ||||||||||
| 31 | 2 | last; | |||||||||
| 32 | } | ||||||||||
| 33 | else | ||||||||||
| 34 | { | ||||||||||
| 35 | 33 | push @newvalue, $value; | |||||||||
| 36 | 33 | ▶ | if( $value !~ /^\s+$/s ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | { | ||||||||||
| 38 | 18 | $words++; | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 4 | ▶ | if( scalar @newvalue < scalar @value ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | { | ||||||||||
| 45 | 2 | push @newvalue, '...'; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 4 | return join '', @newvalue; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | 3 | 1; | |||||||||