lib/oEdtk/FPField.pm

filter: Statementstmt 45.8% 11 / 24 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 43.2% 16 / 37 CC 4 SCAR 18.5
CC
4
Cov
37%
process
12.0
new
6.0
BEGIN
1.0
CRAP 6.4
« blib/lib/oEdtk/FPField.pm ↑ Summary lib/oEdtk/Dict.pm »
1 package oEdtk::FPField;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use base 'oEdtk::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 our $VERSION = 2.1126;
8  
9 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
10 0 my ( $class, $name, $ilen, $flen ) = @_;
11  
12 0 ▶ $flen = 0 if ( !( defined $flen ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flen 0 0 0
13 0 my $self = $class->SUPER::new( $name, $ilen + $flen );
14 0 $self->{'intlen'} = $ilen;
15 0 $self->{'fraclen'} = $flen;
16 0 return $self;
17 }
18  
19 0 ▶sub process {
Subroutine process: not called CC=3 SCAR=24.8
Pod documented
20 0 my ( $self, $data ) = @_;
21  
22 0 $data =~ s/\s+//g;
23 0 my $flen = $self->{'fraclen'};
24 0 ▶ return $data if $data eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $data eq "" 0 0 0
25  
26 0 ▶ if ( $data !~ /\./ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data =~ /\./) 0 0 0
27 0 $data /= 10**$flen;
28 }
29 0 return sprintf( "%.${flen}f", $data );
30 }
31  
32 2 1;
33  
34 =head1 NAME
35  
36 oEdtk::FPField - fixed-point numeric field
37  
38 =head1 SYNOPSIS
39  
40 use oEdtk::FPField;
41  
42 my $field = oEdtk::FPField->new('MONTANT', 8, 2);
43 print $field->process('00012345'), "\n"; # '123.45'
44  
45 =head1 DESCRIPTION
46  
47 An C<oEdtk::Field> subclass for fixed-point numbers. The field is described by
48 an integer length and a fractional length, and C<process> renders the value
49 with exactly the requested number of decimals.
50  
51 =head1 METHODS
52  
53 =head2 new
54  
55 my $field = oEdtk::FPField->new($name, $ilen, $flen);
56  
57 Construct a field whose byte length is C<$ilen + $flen>. C<$flen> defaults to
58 C<0>.
59  
60 =head2 process
61  
62 my $value = $field->process($data);
63  
64 Strip the blanks from C<$data>; an empty value returns C<''>. A value without a
65 decimal point is scaled down by C<10**$flen>, then formatted with C<$flen>
66 decimals.
67  
68 =head1 AUTHOR
69  
70 The oEdtk team.
71  
72 =cut
« blib/lib/oEdtk/FPField.pm ↑ Summary lib/oEdtk/Dict.pm »