blib/lib/Lingua/SRD/Num2Word.pm

filter: Statementstmt 84.8% 56 / 66 Branchbran 75.0% 24 / 32 Conditioncond 41.6% 10 / 24 MC/DCmcdc 21.4% 3 / 14 Subroutinesub 100% 8 / 8 Podpod 50.0% 1 / 2 totaltotal 69.8% 102 / 146 CC 25 SCAR 36.0
CC
25
Cov
74%
num2srd_cardinal
46.8
BEGIN
1.0
BEGIN
1.0
CRAP 36.7
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*-
2  
3 package Lingua::SRD::Num2Word;
4 # ABSTRACT: Number to word conversion in Sardinian (Logudorese)
5  
6 1 ▶use 5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # {{{ use block
11  
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # }}}
16 # {{{ variable declarations
17  
18 1 our $VERSION = '0.2603270';
19  
20 1 my @ONES = qw(zeru unu duos tres bàtoro chimbe ses sete oto noe);
21 1 my @TEENS = qw(deghe undighi doighi treighi batordighi bindighi seighi
22 deghesete degheoto deghenoe);
23 1 my @TENS = qw(_ _ binti trinta baranta chinbanta sessanta setanta otanta nonanta);
24  
25 # Hundreds multiplier prefixes: 2-9
26 1 my @HUN_PREFIX = qw(_ _ du tre bator chinbi ses sete oto nobi);
27  
28 # }}}
29  
30 # {{{ num2srd_cardinal convert number to text
31  
32 sub num2srd_cardinal :Export {
33 66 ▶ my $positive = shift;
Subroutine num2srd_cardinal: called CC=25 SCAR=38.5
Pod documented
34  
35 66 ▶ croak 'You should specify a number from interval [0, 999_999_999]'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999 0 66 66
Condition33%3/9
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999
l!l&&r!l&&!r
0066
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0
l!l&&r!l&&!r
0066
defined $positive && $positive =~ /\A\d+\z/msux
!ll&&!rl&&r
0066
MC/DC0%0/4
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999
defined $positive $positive =~ /\A\d+\z/msux $positive < 0 $positive > 999999999
Truth table20%1/5
not(A && B) or C or D
A= defined $positiveB= $positive =~ /\A\d+\z/msuxC= $positive < 0D= $positive > 999999999
ABCDresult
0XXX1
10XX1
111X1
11011
11000
36 if !defined $positive
37 || $positive !~ m{\A\d+\z}xms
38 || $positive < 0
39 || $positive > 999_999_999;
40  
41 # 0–9
42 66 ▶ return $ONES[$positive] if $positive <= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $positive <= 9 13 53 66
43  
44 # 10–19
45 53 ▶ return $TEENS[$positive - 10] if $positive >= 10 && $positive <= 19;
Branch: 1 branch
BranchTrueFalseTotal
if $positive >= 10 and $positive <= 19 11 42 53
Condition66%2/3
$positive >= 10 and $positive <= 19
!ll&&!rl&&r
04211
MC/DC50%1/2
$positive >= 10 and $positive <= 19
$positive >= 10 $positive <= 19
Truth table66%2/3
A and B
A= $positive >= 10B= $positive <= 19
ABresult
0X0
100
111
46  
47 # 20–99
48 42 ▶ if ($positive >= 20 && $positive <= 99) {
Branch: 1 branch
BranchTrueFalseTotal
if ($positive >= 20 and $positive <= 99) 25 17 42
Condition66%2/3
$positive >= 20 and $positive <= 99
!ll&&!rl&&r
01725
MC/DC50%1/2
$positive >= 20 and $positive <= 99
$positive >= 20 $positive <= 99
Truth table66%2/3
A and B
A= $positive >= 20B= $positive <= 99
ABresult
0X0
100
111
49 25 my $ten_idx = int($positive / 10);
50 25 my $unit = $positive % 10;
51  
52 25 ▶ return $TENS[$ten_idx] if $unit == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $unit == 0 8 17 25
53  
54 17 my $ten_word = $TENS[$ten_idx];
55  
56 # Apocope: tens drop final vowel before "unu"
57 17 ▶ if ($unit == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit == 1) 8 9 17
58 8 $ten_word =~ s/[aeiou]$//;
59 8 return $ten_word . $ONES[$unit];
60 }
61  
62 9 return $ten_word . $ONES[$unit];
63 }
64  
65 # 100–999
66 17 ▶ if ($positive >= 100 && $positive <= 999) {
Branch: 1 branch
BranchTrueFalseTotal
if ($positive >= 100 and $positive <= 999) 13 4 17
Condition66%2/3
$positive >= 100 and $positive <= 999
!ll&&!rl&&r
0413
MC/DC50%1/2
$positive >= 100 and $positive <= 999
$positive >= 100 $positive <= 999
Truth table66%2/3
A and B
A= $positive >= 100B= $positive <= 999
ABresult
0X0
100
111
67 13 my $hun_idx = int($positive / 100);
68 13 my $remain = $positive % 100;
69 13 my $out;
70  
71 13 ▶ if ($hun_idx == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hun_idx == 1) { } 3 10 13
72 3 $out = 'chentu';
73 }
74 else {
75 10 $out = $HUN_PREFIX[$hun_idx] . 'chentos';
76 }
77  
78 13 ▶ $out .= num2srd_cardinal($remain) if $remain;
Branch: 1 branch
BranchTrueFalseTotal
if $remain 4 9 13
79 13 return $out;
80 }
81  
82 # 1_000–999_999
83 4 ▶ if ($positive >= 1_000 && $positive <= 999_999) {
Branch: 1 branch
BranchTrueFalseTotal
if ($positive >= 1000 and $positive <= 999999) 4 0 4
Condition33%1/3
$positive >= 1000 and $positive <= 999999
!ll&&!rl&&r
004
MC/DC0%0/2
$positive >= 1000 and $positive <= 999999
$positive >= 1000 $positive <= 999999
Truth table33%1/3
A and B
A= $positive >= 1000B= $positive <= 999999
ABresult
0X0
100
111
84 4 my $tho_idx = int($positive / 1000);
85 4 my $remain = $positive % 1000;
86 4 my $out;
87  
88 4 ▶ if ($tho_idx == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tho_idx == 1) { } 2 2 4
elsif ($tho_idx == 2) { } 1 1 2
89 2 $out = 'milli';
90 }
91 elsif ($tho_idx == 2) {
92 1 $out = 'duamiza';
93 }
94 else {
95 1 $out = num2srd_cardinal($tho_idx) . 'miza';
96 }
97  
98 4 ▶ $out .= num2srd_cardinal($remain) if $remain;
Branch: 1 branch
BranchTrueFalseTotal
if $remain 1 3 4
99 4 return $out;
100 }
101  
102 # 1_000_000–999_999_999
103 0 ▶ if ($positive >= 1_000_000 && $positive <= 999_999_999) {
Branch: 1 branch
BranchTrueFalseTotal
if ($positive >= 1000000 and $positive <= 999999999) 0 0 0
Condition0%0/3
$positive >= 1000000 and $positive <= 999999999
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 1000000 and $positive <= 999999999
$positive >= 1000000 $positive <= 999999999
Truth table0%0/3
A and B
A= $positive >= 1000000B= $positive <= 999999999
ABresult
0X0
100
111
104 0 my $mil_idx = int($positive / 1_000_000);
105 0 my $remain = $positive % 1_000_000;
106 0 my $out;
107  
108 0 ▶ if ($mil_idx == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mil_idx == 1) { } 0 0 0
109 0 $out = 'unu milione';
110 }
111 else {
112 0 $out = num2srd_cardinal($mil_idx) . ' miliones';
113 }
114  
115 0 ▶ $out .= ' ' . num2srd_cardinal($remain) if $remain;
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
116 0 return $out;
117 }
118  
119 0 return;
120 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
121  
122 # }}}
123  
124 # {{{ capabilities declare supported features
125  
126 sub capabilities {
127 return {
128 1 ▶ cardinal => 1,
Subroutine capabilities: called CC=1 SCAR=0.0
Pod undocumented
129 ordinal => 0,
130 };
131 }
132  
133 # }}}
134 1 1;
135  
136 __END__
↑ Summary