blib/lib/Lingua/HEB/Num2Word.pm

filter: Statementstmt 47.6% 31 / 65 Branchbran 5.5% 2 / 36 Conditioncond 14.8% 4 / 27 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 88.8% 8 / 9 Podpod 50.0% 1 / 2 totaltotal 29.6% 46 / 155 CC 28 SCAR 60.3
CC
28
Cov
29%
num2heb_cardinal
536.1
capabilities
2.0
BEGIN
1.0
CRAP 417.2
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*-
2  
3 package Lingua::HEB::Num2Word;
4 # ABSTRACT: Number to word conversion in Hebrew
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 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # }}}
17 # {{{ variable declarations
18  
19 1 my Readonly::Scalar $COPY = 'Copyright (c) PetaMem, s.r.o. 2002-present';
20 1 our $VERSION = '0.2603270';
21  
22 # }}}
23  
24 # {{{ num2heb_cardinal convert number to text
25  
26 sub num2heb_cardinal :Export {
27 2 ▶ my $positive = shift;
Subroutine num2heb_cardinal: called CC=28 SCAR=62.8
Pod documented
28  
29 2 ▶ 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 2 2
Condition33%3/9
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999
l!l&&r!l&&!r
002
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0
l!l&&r!l&&!r
002
defined $positive && $positive =~ /\A\d+\z/msux
!ll&&!rl&&r
002
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
30 if !defined $positive
31 || $positive !~ m{\A\d+\z}xms
32 || $positive < 0
33 || $positive > 999_999_999;
34  
35 # {{{ tokens
36  
37 # Units 0-10 (masculine/counting form)
38 2 my @units = (
39 'אפס', # 0 efes
40 'אחד', # 1 echad
41 'שניים', # 2 shnayim
42 'שלושה', # 3 shlosha
43 'ארבעה', # 4 arba'a
44 'חמישה', # 5 chamisha
45 'שישה', # 6 shisha
46 'שבעה', # 7 shiv'a
47 'שמונה', # 8 shmona
48 'תשעה', # 9 tish'a
49 'עשרה', # 10 asara
50 );
51  
52 # Teens 11-19 (masculine)
53 2 my @teens = (
54 '', # placeholder for 10
55 'אחד עשר', # 11 achad asar
56 'שנים עשר', # 12 shneym asar
57 'שלושה עשר', # 13 shlosha asar
58 'ארבעה עשר', # 14 arba'a asar
59 'חמישה עשר', # 15 chamisha asar
60 'שישה עשר', # 16 shisha asar
61 'שבעה עשר', # 17 shiv'a asar
62 'שמונה עשר', # 18 shmona asar
63 'תשעה עשר', # 19 tish'a asar
64 );
65  
66 # Tens 20-90
67 2 my @tens = (
68 '', # placeholder
69 '', # placeholder
70 'עשרים', # 20 esrim
71 'שלושים', # 30 shloshim
72 'ארבעים', # 40 arba'im
73 'חמישים', # 50 chamishim
74 'שישים', # 60 shishim
75 'שבעים', # 70 shiv'im
76 'שמונים', # 80 shmonim
77 'תשעים', # 90 tish'im
78 );
79  
80 # Construct forms for hundreds (3-9 before מאות)
81 2 my @hund_prefix = (
82 '', # 0
83 '', # 1 - special case מאה
84 '', # 2 - special case מאתיים
85 'שלוש', # 3 shlosh
86 'ארבע', # 4 arba
87 'חמש', # 5 chamesh
88 'שש', # 6 shesh
89 'שבע', # 7 shva
90 'שמונה', # 8 shmone
91 'תשע', # 9 tsha
92 );
93  
94 # Construct forms for thousands (3-9 before אלפים)
95 2 my @thou_prefix = (
96 '', # 0
97 '', # 1 - special case אלף
98 '', # 2 - special case אלפיים
99 'שלושת', # 3 shloshet
100 'ארבעת', # 4 arba'at
101 'חמשת', # 5 chameshet
102 'ששת', # 6 sheshet
103 'שבעת', # 7 shiv'at
104 'שמונת', # 8 shmonat
105 'תשעת', # 9 tish'at
106 );
107  
108 # }}}
109  
110 2 ▶ return $units[$positive] if ($positive >= 0 && $positive <= 10);
Branch: 1 branch
BranchTrueFalseTotal
if $positive >= 0 and $positive <= 10 2 0 2
Condition33%1/3
$positive >= 0 and $positive <= 10
!ll&&!rl&&r
002
MC/DC0%0/2
$positive >= 0 and $positive <= 10
$positive >= 0 $positive <= 10
Truth table33%1/3
A and B
A= $positive >= 0B= $positive <= 10
ABresult
0X0
100
111
111 0 ▶ return $teens[$positive - 10] if ($positive > 10 && $positive < 20);
Branch: 1 branch
BranchTrueFalseTotal
if $positive > 10 and $positive < 20 0 0 0
Condition0%0/3
$positive > 10 and $positive < 20
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 10 and $positive < 20
$positive > 10 $positive < 20
Truth table0%0/3
A and B
A= $positive > 10B= $positive < 20
ABresult
0X0
100
111
112  
113 0 my $out;
114  
115 0 ▶ if ($positive >= 20 && $positive < 100) { # 20 .. 99
Branch: 5 branches
BranchTrueFalseTotal
if ($positive >= 20 and $positive < 100) { } 0 0 0
elsif ($positive == 100) { } 0 0 0
elsif ($positive > 100 and $positive < 1000) { } 0 0 0
elsif ($positive >= 1000 and $positive < 1000000) { } 0 0 0
elsif ($positive >= 1000000 and $positive < 1000000000) { } 0 0 0
Condition0%0/3
$positive >= 20 and $positive < 100
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 20 and $positive < 100
$positive >= 20 $positive < 100
Truth table0%0/3
A and B
A= $positive >= 20B= $positive < 100
ABresult
0X0
100
111
116 0 my $ten_idx = int($positive / 10);
117 0 my $remain = $positive % 10;
118  
119 0 $out = $tens[$ten_idx];
120 0 ▶ $out .= ' ו' . $units[$remain] if $remain;
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
121 }
122 elsif ($positive == 100) { # 100
123 0 $out = 'מאה';
124 }
125 ▶ elsif ($positive > 100 && $positive < 1000) { # 101 .. 999
Condition0%0/3
$positive > 100 and $positive < 1000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 100 and $positive < 1000
$positive > 100 $positive < 1000
Truth table0%0/3
A and B
A= $positive > 100B= $positive < 1000
ABresult
0X0
100
111
126 0 my $hund_idx = int($positive / 100);
127 0 my $remain = $positive % 100;
128  
129 0 ▶ if ($hund_idx == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($hund_idx == 1) { } 0 0 0
elsif ($hund_idx == 2) { } 0 0 0
130 0 $out = 'מאה';
131 }
132 elsif ($hund_idx == 2) {
133 0 $out = 'מאתיים';
134 }
135 else {
136 0 $out = "$hund_prefix[$hund_idx] מאות";
137 }
138  
139 0 ▶ if ($remain) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remain) 0 0 0
140 0 $out .= ' ' . num2heb_cardinal($remain);
141 }
142 }
143 ▶ elsif ($positive >= 1000 && $positive < 1_000_000) { # 1000 .. 999_999
Condition0%0/3
$positive >= 1000 and $positive < 1000000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 1000 and $positive < 1000000
$positive >= 1000 $positive < 1000000
Truth table0%0/3
A and B
A= $positive >= 1000B= $positive < 1000000
ABresult
0X0
100
111
144 0 my $thou_idx = int($positive / 1000);
145 0 my $remain = $positive % 1000;
146  
147 0 ▶ if ($thou_idx == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($thou_idx == 1) { } 0 0 0
elsif ($thou_idx == 2) { } 0 0 0
elsif ($thou_idx < 10) { } 0 0 0
148 0 $out = 'אלף';
149 }
150 elsif ($thou_idx == 2) {
151 0 $out = 'אלפיים';
152 }
153 elsif ($thou_idx < 10) {
154 0 $out = "$thou_prefix[$thou_idx] אלפים";
155 }
156 else {
157 # thou_idx >= 10, recursively convert the thousands multiplier
158 0 $out = num2heb_cardinal($thou_idx) . ' אלף';
159 }
160  
161 0 ▶ if ($remain) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remain) 0 0 0
162 0 $out .= ' ' . num2heb_cardinal($remain);
163 }
164 }
165 ▶ elsif ($positive >= 1_000_000 && $positive < 1_000_000_000) { # 1_000_000 .. 999_999_999
Condition0%0/3
$positive >= 1000000 and $positive < 1000000000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 1000000 and $positive < 1000000000
$positive >= 1000000 $positive < 1000000000
Truth table0%0/3
A and B
A= $positive >= 1000000B= $positive < 1000000000
ABresult
0X0
100
111
166 0 my $mil_idx = int($positive / 1_000_000);
167 0 my $remain = $positive % 1_000_000;
168  
169 0 ▶ if ($mil_idx == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mil_idx == 1) { } 0 0 0
170 0 $out = 'מיליון';
171 }
172 else {
173 0 $out = num2heb_cardinal($mil_idx) . ' מיליון';
174 }
175  
176 0 ▶ if ($remain) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remain) 0 0 0
177 0 $out .= ' ' . num2heb_cardinal($remain);
178 }
179 }
180  
181 0 return $out;
182 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
183  
184 # }}}
185  
186  
187 # {{{ capabilities declare supported features
188  
189 sub capabilities {
190 return {
191 0 ▶ cardinal => 1,
Subroutine capabilities: not called CC=1 SCAR=6.9
Pod undocumented
192 ordinal => 0,
193 };
194 }
195  
196 # }}}
197 1 1;
198  
199 __END__
↑ Summary