ODS/Table/Column/Float.pm untested

filter: Statementstmt 0.0% 0 / 20 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 39 CC 4 SCAR 16.9
CC
4
Cov
0%
validation
6.0
inflation
6.0
deflation
6.0
CRAP 5.4
1 package ODS::Table::Column::Float;
2  
3 extends 'ODS::Table::Column::Base';
4  
5 use ODS::Utils qw/error/;
6  
7 has precision => isa(integer);
8  
9 has number => isa(boolean);
10  
11 sub validation {
12 if (ref($_[1]) || ${$_[1]} !~ m/\d+(\.\d+)?/) {
13 croak sprintf "The value passed to the %s column does not match the float constraint.",
14 $_[0]->name;
15 }
16 return $_[1];
17 }
18  
19 sub inflation {
20 my ($self, $value) = @_;
21 if ($self->precision) {
22 my $precision = '%.' . $self->precision . 'f';
23 $value = sprintf($precision, $value);
24 }
25 return $value;
26 }
27  
28 sub deflation {
29 my ($self, $value) = @_;
30 if ($_[0]->number && $_[0]->precision) {
31 $value = 0 + $value;
32 }
33 return $value;
34 }
35  
36 1;
37  
38 __END__