lib/oEdtk/SignedField.pm

filter: Statementstmt 100% 31 / 31 Branchbran 90.0% 9 / 10 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 94.3% 50 / 53 CC 7 SCAR 13.6
CC
7
Cov
95%
process
6.0
new
2.0
BEGIN
1.0
CRAP 3.9
« lib/oEdtk/FixIdx.pm ↑ Summary blib/lib/oEdtk/Emailing.pm »
1 package oEdtk::SignedField;
2  
3 # Decode a signed amount field encoded using Infinite conventions.
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use base 'oEdtk::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 our $VERSION = 2.1129;
10  
11 3 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
12 3 my ( $class, $name, $ilen, $flen ) = @_;
13  
14 3 ▶ $flen = 0 unless defined($flen);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flen 0 3 3
15 3 my $self = $class->SUPER::new( $name, $ilen + $flen );
16 3 $self->{'intlen'} = $ilen;
17 3 $self->{'fraclen'} = $flen;
18 3 return $self;
19 }
20  
21 6 ▶sub process {
Subroutine process: called CC=6 SCAR=17.9
Pod documented
22 6 my ( $self, $data ) = @_;
23  
24 6 $data =~ s/\s+//g;
25  
26 6 ▶ if ( $data !~ /^-?\d*[p-y]?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data =~ /^-?\d*[p-y]?$/) 1 5 6
27 1 warn "INFO: Unexpected numerical value: $data in " . $self->{'name'} . "\n";
28 }
29  
30 6 ▶ if ( $data eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data eq "") 1 5 6
31 1 $data = 0;
32 }
33 6 ▶ if ( $data =~ s/([p-y])$/ord($1) - ord('p')/e ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ s/([p-y])$/ord($1) - 112;/e) 3 3 6
34 3 $data *= -1;
35 }
36  
37 6 my $flen = $self->{'fraclen'};
38 6 ▶ if ( $data !~ /\./ && $flen > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $data =~ /\./ and $flen > 0) 4 2 6
Condition66%2/3
not $data =~ /\./ and $flen > 0
!ll&&!rl&&r
024
MC/DC50%1/2
not $data =~ /\./ and $flen > 0
not $data =~ /\./ $flen > 0
Truth table66%2/3
not(A) and B
A= not $data =~ /\./B= $flen > 0
ABresult
0X0
100
111
39 4 $data /= 10**$flen;
40 4 return sprintf( "%.${flen}f", $data );
41 }
42 2 return $data;
43 }
44  
45 3 1;
46  
47 =head1 NAME
48  
49 oEdtk::SignedField - signed amount field (Infinite encoding)
50  
51 =head1 SYNOPSIS
52  
53 use oEdtk::SignedField;
54  
55 my $field = oEdtk::SignedField->new('MONTANT', 8, 2);
56 print $field->process('00001234'), "\n"; # '12.34'
57  
58 =head1 DESCRIPTION
59  
60 An C<oEdtk::Field> subclass decoding a signed amount that follows the Infinite
61 convention: the trailing byte, when it is a letter in the range C<p>..C<y>,
62 both carries the last digit and marks the amount negative. A value whose shape
63 does not match the expected form raises a warning.
64  
65 =head1 METHODS
66  
67 =head2 new
68  
69 my $field = oEdtk::SignedField->new($name, $ilen, $flen);
70  
71 Construct a field whose byte length is C<$ilen + $flen>. C<$flen> defaults to
72 C<0>.
73  
74 =head2 process
75  
76 my $value = $field->process($data);
77  
78 Strip the blanks from C<$data>; warn when it is not a plain (optionally signed)
79 number with an optional trailing C<p>..C<y> letter. An empty value becomes
80 C<0>; a trailing C<p>..C<y> letter replaces the last digit with its value and
81 negates the amount. When C<$flen> is set the value is scaled and formatted with
82 C<$flen> decimals.
83  
84 =head1 AUTHOR
85  
86 The oEdtk team.
87  
88 =cut
« lib/oEdtk/FixIdx.pm ↑ Summary blib/lib/oEdtk/Emailing.pm »