blib/lib/DTL/Fast/Filter/Center.pm

filter: Statementstmt 96.5% 28 / 29 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 84.4% 38 / 45 SCAR 13.9
CC
4
Cov
89%
filter
3.1
parse_parameters
2.0
BEGIN
1.0
CRAP 4.0
« blib/lib/DTL/Fast/Filter.pm ↑ Summary blib/lib/DTL/Fast/Filter/Split.pm »
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
BranchTrueFalseTotal
unless scalar @{$self->{"parameter"};} 0 8 8
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
BranchTrueFalseTotal
if ($width =~ /^\d+$/) { } 8 0 8
25 {
26 8 my $adjustment = ($width - length $value);
27 8 ▶ if( $adjustment > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($adjustment > 0) 8 0 8
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;
« blib/lib/DTL/Fast/Filter.pm ↑ Summary blib/lib/DTL/Fast/Filter/Split.pm »