| 1 | package DTL::Fast::Filter::Wordwrap; | ||||||||||||||
| 2 | 2 | ▶ | 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 | 2 | ▶ | use parent 'DTL::Fast::Filter'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 2 | $DTL::Fast::FILTER_HANDLERS{'wordwrap'} = __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 wrapping width specified") | ||||||||||||||
| 12 | 4 | ▶ | if not scalar @{$self->{'parameter'}}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 13 | 4 | $self->{'maxwidth'} = $self->{'parameter'}->[0]; | |||||||||||||
| 14 | 4 | return $self; | |||||||||||||
| 15 | } | ||||||||||||||
| 16 | |||||||||||||||
| 17 | |||||||||||||||
| 18 | #@Override | ||||||||||||||
| 19 | sub filter | ||||||||||||||
| 20 | { | ||||||||||||||
| 21 | 4 | ▶ | my($self, $filter_manager, $value, $context ) = @_; | ||||||||||||
|
Subroutine
filter: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||
| 22 | |||||||||||||||
| 23 | 4 | my $maxwidth = $self->{'maxwidth'}->render($context); | |||||||||||||
| 24 | 4 | my @value = split /\s+/s, $value; | |||||||||||||
| 25 | 4 | my @result = (); | |||||||||||||
| 26 | 4 | my $width = 0; | |||||||||||||
| 27 | |||||||||||||||
| 28 | 4 | foreach my $value (@value) | |||||||||||||
| 29 | { | ||||||||||||||
| 30 | 31 | my $length = length $value; | |||||||||||||
| 31 | 31 | ▶ | if( $width == 0 ) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 32 | { | ||||||||||||||
| 33 | 4 | push @result, $value; | |||||||||||||
| 34 | 4 | $width += $length; | |||||||||||||
| 35 | } | ||||||||||||||
| 36 | elsif( $length + $width + 1 > $maxwidth ) | ||||||||||||||
| 37 | { | ||||||||||||||
| 38 | 15 | push @result, "\n", $value; | |||||||||||||
| 39 | 15 | $width = $length; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | else | ||||||||||||||
| 42 | { | ||||||||||||||
| 43 | 12 | push @result, ' ', $value; | |||||||||||||
| 44 | 12 | $width += $length + 1; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 4 | return join '', @result; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 2 | 1; | |||||||||||||