File Coverage

blib/lib/DTL/Fast/Filter/Floatformat.pm
Criterion Covered Total %
statement 24 24 100.0
branch 6 6 100.0
condition 2 3 66.6
subroutine 6 6 100.0
pod 0 2 0.0
total 38 41 92.6


line stmt bran cond sub pod time code
1             package DTL::Fast::Filter::Floatformat;
2 2     2   1269 use strict; use utf8; use warnings FATAL => 'all';
  2     2   5  
  2     2   53  
  2         9  
  2         4  
  2         11  
  2         47  
  2         4  
  2         77  
3 2     2   15 use parent 'DTL::Fast::Filter';
  2         2  
  2         13  
4              
5             $DTL::Fast::FILTER_HANDLERS{'floatformat'} = __PACKAGE__;
6              
7             #@Override
8             sub parse_parameters
9             {
10 12     12 0 17 my $self = shift;
11             $self->{'digits'} = $self->{'parameter'}->[0]
12 12 100       14 if scalar @{$self->{'parameter'}};
  12         39  
13 12         38 return $self;
14             }
15              
16             #@Override
17             sub filter
18             {
19 12     12 0 15 my $self = shift; # self
20 12         12 shift; # filter_manager
21 12         15 my $value = shift;
22 12         14 my $context = shift;
23              
24 12 100       38 my $digits = defined $self->{'digits'} ? $self->{'digits'}->render($context) : undef;
25            
26 12 100 66     65 if(
27             defined $digits
28             and $digits =~ /^\d+$/
29             )
30             {
31 8         59 $value = sprintf "%.0${digits}f", $value;
32             }
33            
34 12         43 return $value;
35             }
36              
37             1;