lib/oEdtk/FPField.pm

filter: Statementstmt 100% 24 / 24 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 97.3% 36 / 37 CC 4 SCAR 6.9
CC
4
Cov
97%
process
3.0
new
2.0
BEGIN
1.0
CRAP 2.0
« blib/lib/oEdtk/lib/tracking_Statistics.pl ↑ Summary blib/lib/oEdtk/XML/DTD/Utils.pm »
1 package oEdtk::FPField;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use base 'oEdtk::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 our $VERSION = 2.1131;
8  
9 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
10 2 my ( $class, $name, $ilen, $flen ) = @_;
11  
12 2 ▶ $flen = 0 if ( !( defined $flen ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flen 0 2 2
13 2 my $self = $class->SUPER::new( $name, $ilen + $flen );
14 2 $self->{'intlen'} = $ilen;
15 2 $self->{'fraclen'} = $flen;
16 2 return $self;
17 }
18  
19 6 ▶sub process {
Subroutine process: called CC=3 SCAR=11.0
Pod documented
20 6 my ( $self, $data ) = @_;
21  
22 6 $data =~ s/\s+//g;
23 6 my $flen = $self->{'fraclen'};
24 6 ▶ return $data if $data eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $data eq "" 1 5 6
25  
26 5 ▶ if ( $data !~ /\./ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data =~ /\./) 3 2 5
27 3 $data /= 10**$flen;
28 }
29 5 return sprintf( "%.${flen}f", $data );
30 }
31  
32 3 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/lib/tracking_Statistics.pl ↑ Summary blib/lib/oEdtk/XML/DTD/Utils.pm »