| 1 | package DTL::Fast::Filter::Center; | ||||||||||
| 2 | 4 | ▶ | 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 | 4 | ▶ | use parent 'DTL::Fast::Filter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 4 | $DTL::Fast::FILTER_HANDLERS{'center'} = __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 width specified for adjusting") | ||||||||||
| 12 | 8 | ▶ | if not scalar @{$self->{'parameter'}}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 8 | $self->{'width'} = $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=3 SCAR=11.4
Pod
undocumented
| |||||||||||
| 21 | |||||||||||
| 22 | 8 | my $width = $self->{'width'}->render($context); | |||||||||
| 23 | |||||||||||
| 24 | 8 | ▶ | if( $width =~ /^\d+$/ ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | { | ||||||||||
| 26 | 8 | my $adjustment = ($width - length $value); | |||||||||
| 27 | 8 | ▶ | if( $adjustment > 0 ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | { | ||||||||||
| 29 | 8 | $value = $self->adjust($value, $adjustment); | |||||||||
| 30 | } | ||||||||||
| 31 | } | ||||||||||
| 32 | else | ||||||||||
| 33 | { | ||||||||||
| 34 | 0 | die $self->get_render_error("Argument must be a positive number, not '$width'"); | |||||||||
| 35 | } | ||||||||||
| 36 | 8 | return $value; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | sub adjust | ||||||||||
| 40 | { | ||||||||||
| 41 | 4 | ▶ | my ($self, $value, $adjustment) = @_; | ||||||||
|
Subroutine
adjust: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 42 | 4 | return (' 'x int($adjustment/2)).$value; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 4 | 1; | |||||||||