blib/lib/Lingua/ELL/Num2Word.pm

filter: Statementstmt 50.0% 30 / 60 Branchbran 5.8% 2 / 34 Conditioncond 11.1% 4 / 36 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 88.8% 8 / 9 Podpod 50.0% 1 / 2 totaltotal 27.6% 45 / 163 CC 30 SCAR 62.2
CC
30
Cov
28%
num2ell_cardinal
637.8
capabilities
2.0
BEGIN
1.0
CRAP 503.8
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*-
2  
3 package Lingua::ELL::Num2Word;
4 # ABSTRACT: Number to word conversion in Greek
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. 2004-present';
20 1 our $VERSION = '0.2603270';
21  
22 # }}}
23  
24 # {{{ num2ell_cardinal convert number to text
25  
26 sub num2ell_cardinal :Export {
27 2 ▶ my $positive = shift;
Subroutine num2ell_cardinal: called CC=30 SCAR=64.6
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 2 my @ones = qw(μηδέν ένα δύο τρία τέσσερα πέντε έξι επτά οκτώ εννέα δέκα έντεκα δώδεκα);
36 2 my @teens = (
37 'δεκατρία', # 13
38 'δεκατέσσερα', # 14
39 'δεκαπέντε', # 15
40 'δεκαέξι', # 16
41 'δεκαεπτά', # 17
42 'δεκαοκτώ', # 18
43 'δεκαεννέα', # 19
44 );
45 2 my @tens = qw(είκοσι τριάντα σαράντα πενήντα εξήντα εβδομήντα ογδόντα ενενήντα);
46 2 my @hundreds = (
47 'εκατό', # 100
48 'διακόσια', # 200
49 'τριακόσια', # 300
50 'τετρακόσια', # 400
51 'πεντακόσια', # 500
52 'εξακόσια', # 600
53 'επτακόσια', # 700
54 'οκτακόσια', # 800
55 'εννιακόσια', # 900
56 );
57  
58 2 ▶ return $ones[$positive] if ($positive >= 0 && $positive < 13);
Branch: 1 branch
BranchTrueFalseTotal
if $positive >= 0 and $positive < 13 2 0 2
Condition33%1/3
$positive >= 0 and $positive < 13
!ll&&!rl&&r
002
MC/DC0%0/2
$positive >= 0 and $positive < 13
$positive >= 0 $positive < 13
Truth table33%1/3
A and B
A= $positive >= 0B= $positive < 13
ABresult
0X0
100
111
59 0 ▶ return $teens[$positive - 13] if ($positive >= 13 && $positive < 20);
Branch: 1 branch
BranchTrueFalseTotal
if $positive >= 13 and $positive < 20 0 0 0
Condition0%0/3
$positive >= 13 and $positive < 20
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 13 and $positive < 20
$positive >= 13 $positive < 20
Truth table0%0/3
A and B
A= $positive >= 13B= $positive < 20
ABresult
0X0
100
111
60  
61 0 my $out;
62 my $remain;
63  
64 0 ▶ if ($positive > 19 && $positive < 100) { # 20 .. 99
Branch: 8 branches
BranchTrueFalseTotal
if ($positive > 19 and $positive < 100) { } 0 0 0
elsif ($positive == 100) { } 0 0 0
elsif ($positive > 100 and $positive < 200) { } 0 0 0
elsif ($positive >= 200 and $positive < 1000) { } 0 0 0
elsif ($positive >= 1000 and $positive < 2000) { } 0 0 0
elsif ($positive >= 2000 and $positive < 1000000) { } 0 0 0
elsif ($positive >= 1000000 and $positive < 2000000) { } 0 0 0
elsif ($positive >= 2000000 and $positive < 1000000000) { } 0 0 0
Condition0%0/3
$positive > 19 and $positive < 100
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 19 and $positive < 100
$positive > 19 $positive < 100
Truth table0%0/3
A and B
A= $positive > 19B= $positive < 100
ABresult
0X0
100
111
65 0 my $ten_idx = int($positive / 10) - 2;
66 0 $remain = $positive % 10;
67  
68 0 $out = $tens[$ten_idx];
69 0 ▶ $out .= ' ' . $ones[$remain] if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
70 }
71 elsif ($positive == 100) { # 100
72 0 $out = 'εκατό';
73 }
74 ▶ elsif ($positive > 100 && $positive < 200) { # 101 .. 199
Condition0%0/3
$positive > 100 and $positive < 200
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 100 and $positive < 200
$positive > 100 $positive < 200
Truth table0%0/3
A and B
A= $positive > 100B= $positive < 200
ABresult
0X0
100
111
75 0 $remain = $positive % 100;
76 0 $out = 'εκατόν ' . num2ell_cardinal($remain);
77 }
78 ▶ elsif ($positive >= 200 && $positive < 1000) { # 200 .. 999
Condition0%0/3
$positive >= 200 and $positive < 1000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 200 and $positive < 1000
$positive >= 200 $positive < 1000
Truth table0%0/3
A and B
A= $positive >= 200B= $positive < 1000
ABresult
0X0
100
111
79 0 my $h_idx = int($positive / 100) - 1;
80 0 $remain = $positive % 100;
81  
82 0 $out = $hundreds[$h_idx];
83 0 ▶ $out .= ' ' . num2ell_cardinal($remain) if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
84 }
85 ▶ elsif ($positive >= 1000 && $positive < 2000) { # 1000 .. 1999
Condition0%0/3
$positive >= 1000 and $positive < 2000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 1000 and $positive < 2000
$positive >= 1000 $positive < 2000
Truth table0%0/3
A and B
A= $positive >= 1000B= $positive < 2000
ABresult
0X0
100
111
86 0 $remain = $positive % 1000;
87  
88 0 $out = 'χίλια';
89 0 ▶ $out .= ' ' . num2ell_cardinal($remain) if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
90 }
91 ▶ elsif ($positive >= 2000 && $positive < 1_000_000) { # 2000 .. 999_999
Condition0%0/3
$positive >= 2000 and $positive < 1000000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 2000 and $positive < 1000000
$positive >= 2000 $positive < 1000000
Truth table0%0/3
A and B
A= $positive >= 2000B= $positive < 1000000
ABresult
0X0
100
111
92 0 my $k_val = int($positive / 1000);
93 0 $remain = $positive % 1000;
94  
95 0 $out = num2ell_cardinal($k_val) . ' χιλιάδες';
96 0 ▶ $out .= ' ' . num2ell_cardinal($remain) if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
97 }
98 ▶ elsif ($positive >= 1_000_000 && $positive < 2_000_000) { # 1_000_000 .. 1_999_999
Condition0%0/3
$positive >= 1000000 and $positive < 2000000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 1000000 and $positive < 2000000
$positive >= 1000000 $positive < 2000000
Truth table0%0/3
A and B
A= $positive >= 1000000B= $positive < 2000000
ABresult
0X0
100
111
99 0 $remain = $positive % 1_000_000;
100  
101 0 $out = 'ένα εκατομμύριο';
102 0 ▶ $out .= ' ' . num2ell_cardinal($remain) if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
103 }
104 ▶ elsif ($positive >= 2_000_000 && $positive < 1_000_000_000) { # 2_000_000 .. 999_999_999
Condition0%0/3
$positive >= 2000000 and $positive < 1000000000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 2000000 and $positive < 1000000000
$positive >= 2000000 $positive < 1000000000
Truth table0%0/3
A and B
A= $positive >= 2000000B= $positive < 1000000000
ABresult
0X0
100
111
105 0 my $m_val = int($positive / 1_000_000);
106 0 $remain = $positive % 1_000_000;
107  
108 0 $out = num2ell_cardinal($m_val) . ' εκατομμύρια';
109 0 ▶ $out .= ' ' . num2ell_cardinal($remain) if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
110 }
111  
112 0 return $out;
113 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 # }}}
116  
117  
118 # {{{ capabilities declare supported features
119  
120 sub capabilities {
121 return {
122 0 ▶ cardinal => 1,
Subroutine capabilities: not called CC=1 SCAR=6.9
Pod undocumented
123 ordinal => 0,
124 };
125 }
126  
127 # }}}
128 1 1;
129  
130 __END__
↑ Summary