TLH/Numbers.pm

filter: Statementstmt 100% 50 / 50 Branchbran 87.5% 14 / 16 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 97.8% 89 / 91 CC 13 SCAR 20.4
CC
13
Cov
97%
num2tlh
12.0
num2tlh_ordinal
2.0
BEGIN
1.0
CRAP 7.7
↑ Summary EO/Numbers.pm »
1 package Lingua::TLH::Numbers;
2  
3 3 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Regexp::Common qw( number );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 our @EXPORT_OK = qw( num2tlh num2tlh_ordinal );
11 3 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
12  
13 3 our $VERSION = '0.01';
14  
15 # up to 9 million supported
16 3 Readonly my $MAX_INT_DIGITS => 7;
17  
18 3 Readonly my $EMPTY_STR => q{};
19 3 Readonly my $SPACE => q{ };
20 3 Readonly my $MINUS => q{-};
21  
22 3 Readonly my $POINT => q{vI'};
23 3 Readonly my $ORDINAL_SUFFIX => q{DIch};
24  
25 3 Readonly my @NAMES1 => qw< pagh wa' cha' wej loS vagh jav Soch chorgh Hut >;
26 3 Readonly my @NAMES2 => $EMPTY_STR, qw< maH vatlh SaD netlh bIp 'uy' >;
27  
28 # convert number to words
29 84 ▶sub num2tlh {
Subroutine num2tlh: called CC=12 SCAR=24.9
Pod documented
30 84 my ($number) = @_;
31 84 my $digit_count = 0;
32 84 my @names;
33  
34 84 ▶ return unless defined $number;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 1 83 84
35  
36 # NaN and inf not supported
37 83 ▶ return if $number eq 'NaN' || $number =~ m{^ [-+]? inf $}ix;
Branch: 1 branch
BranchTrueFalseTotal
if $number eq "NaN" or $number =~ /^ [-+]? inf $/xi 4 79 83
Condition100%3/3
$number eq "NaN" or $number =~ /^ [-+]? inf $/xi
l!l&&r!l&&!r
1379
MC/DC100%2/2
$number eq "NaN" or $number =~ /^ [-+]? inf $/xi
$number eq "NaN" $number =~ /^ [-+]? inf $/xi
Truth table100%3/3
A or B
A= $number eq "NaN"B= $number =~ /^ [-+]? inf $/xi
ABresult
1X1
011
000
38  
39 79 ▶ return if $number !~ m{^ $RE{num}{real}{-keep} $}x;
Branch: 1 branch
BranchTrueFalseTotal
unless $number =~ /^ $Lingua::TLH::Numbers::RE{"num"}{"real"}{"-keep"} $/x 6 73 79
40 73 my ($sign, $int, $frac) = ($2, $4, $6);
41  
42 # negatives not supported
43 73 ▶ return if $sign eq $MINUS;
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq $MINUS 7 66 73
44  
45 66 ▶ return if length $int > $MAX_INT_DIGITS;
Branch: 1 branch
BranchTrueFalseTotal
if length $int > $MAX_INT_DIGITS 0 66 66
46  
47 # integer
48 DIGIT:
49 66 for my $digit (reverse split $EMPTY_STR, $int) {
50 # skip zero unless it is the only digit
51 198 ▶ next DIGIT if $digit == 0 && $int != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $digit == 0 and $int != 0 106 92 198
Condition100%3/3
$digit == 0 and $int != 0
!ll&&!rl&&r
839106
MC/DC100%2/2
$digit == 0 and $int != 0
$digit == 0 $int != 0
Truth table100%3/3
A and B
A= $digit == 0B= $int != 0
ABresult
0X0
100
111
52  
53 92 unshift @names, $NAMES1[$digit] . $NAMES2[$digit_count];
54 }
55 continue {
56 198 $digit_count++;
57 }
58  
59 # fraction
60 66 ▶ if (defined $frac && $frac ne $EMPTY_STR) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $frac and $frac ne $EMPTY_STR) 12 54 66
Condition100%3/3
defined $frac and $frac ne $EMPTY_STR
!ll&&!rl&&r
52212
MC/DC100%2/2
defined $frac and $frac ne $EMPTY_STR
defined $frac $frac ne $EMPTY_STR
Truth table100%3/3
A and B
A= defined $fracB= $frac ne $EMPTY_STR
ABresult
0X0
100
111
61 12 push @names, $POINT, map { $NAMES1[$_] } split $EMPTY_STR, $frac;
62 }
63  
64 66 return join $SPACE, @names;
65 }
66  
67 # convert number to ordinal words
68 23 ▶sub num2tlh_ordinal {
Subroutine num2tlh_ordinal: called CC=2 SCAR=7.0
Pod documented
69 23 my ($number) = @_;
70 23 my $name = num2tlh($number);
71  
72 23 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 23 23
73 23 return $name . $ORDINAL_SUFFIX;
74 }
75  
76 3 1;
77  
78 __END__
↑ Summary EO/Numbers.pm »