blib/lib/Lingua/ITA/Word2Num.pm

filter: Statementstmt 100% 26 / 26 Branchbran n/a Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 39 / 39 CC 2 SCAR 2.0
CC
2
Cov
100%
w2n
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8; -*-
2  
3 package Lingua::ITA::Word2Num;
4 # ABSTRACT: Word to number conversion in Italian
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 Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Parse::RecDescent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # }}}
16 # {{{ var block
17 1 our $VERSION = '0.2603270';
18 1 our @EXPORT_OK = qw(cardinal2num w2n);
19 1 my $parser = ita_numerals();
20  
21 # }}}
22  
23 # {{{ w2n convert text to number
24  
25 sub w2n :Export {
26 3 ▶ my $input = shift // return;
Subroutine w2n: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
shift() // (return)
l!l
21
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
27  
28 2 $input =~ s/,//g;
29 2 $input =~ s/ //g;
30  
31 2 return $parser->numeral($input);
32 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
33 # }}}
34 # {{{ ita_numerals create parser for numerals
35  
36 sub ita_numerals {
37 1 ▶ return Parse::RecDescent->new(q{
Subroutine ita_numerals: called CC=1 SCAR=0.0
Pod documented
38 <autoaction: { $item[1] } >
39  
40 numeral: mega
41 | kOhOd
42 | 'zero' { 0 }
43 | { }
44  
45 number:
46 'undici' { 11 }
47 | 'tredici' { 13 }
48 | 'un' { 1 }
49 | 'due' { 2 }
50 | 'tre' { 3 }
51 | 'quattro' { 4 }
52 | 'cinque' { 5 }
53 | 'sei' { 6 }
54 | 'sette' { 7 }
55 | 'otto' { 8 }
56 | 'nove' { 9 }
57 | 'dieci' { 10 }
58 | 'dodici' { 12 }
59 | 'quattordici' { 14 }
60 | 'quindici' { 15 }
61 | 'sedici' { 16 }
62 | 'diciassette' { 17 }
63 | 'diciotto' { 18 }
64 | 'diciannove' { 19 }
65  
66 tens: 'venti' { 20 }
67 | /ventuno?/ { 21 }
68 | 'ventotto' { 28 }
69 | 'trenta' { 30 }
70 | 'trent' { 30 }
71 | 'quaranta' { 40 }
72 | 'quarant' { 40 }
73 | 'cinquanta' { 50 }
74 | 'cinquant' { 50 }
75 | 'sessanta' { 60 }
76 | 'sessant' { 60 }
77 | 'settanta' { 70 }
78 | 'settant' { 70 }
79 | 'ottanta' { 80 }
80 | 'ottant' { 80 }
81 | 'novanta' { 90 }
82 | 'novant' { 90 }
83  
84 deca: tens number { $item[1] + $item[2] }
85 | tens
86 | number
87  
88 hecto: number /cento/ deca { $item[1] * 100 + $item[3] }
89 | number /cento/ { $item[1] * 100 }
90 | /cento/ deca { 100 + $item[2] }
91 | 'cento' { 100 }
92  
93 hOd: hecto
94 | deca
95  
96 kilo: hOd /mill?[ae]/ hOd { $item[1] * 1000 + $item[3] }
97 | hOd /mill?[ae]/ { $item[1] * 1000 }
98 | /mill?[ae]/ hOd { 1000 + $item[2] }
99 | /mill?[ae]/ { 1000 }
100  
101 kOhOd: kilo
102 | hOd
103  
104 mega: kOhOd /mill?ion[ei]/ kOhOd { $item[1] * 1_000_000 + $item[3] }
105  
106 });
107 }
108 # }}}
109  
110 1 1;
111  
112 __END__
↑ Summary