blib/lib/Lingua/CAT/Num2Word.pm

filter: Statementstmt 43.9% 29 / 66 Branchbran 6.2% 2 / 32 Conditioncond 13.3% 4 / 30 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 88.8% 8 / 9 Podpod 50.0% 1 / 2 totaltotal 28.0% 44 / 157 CC 27 SCAR 60.2
CC
27
Cov
27%
num2cat_cardinal
531.7
capabilities
2.0
BEGIN
1.0
CRAP 410.4
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*-
2  
3 package Lingua::CAT::Num2Word;
4 # ABSTRACT: Number to word conversion in Catalan
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 # {{{ num2cat_cardinal convert number to text
25  
26 sub num2cat_cardinal :Export {
27 2 ▶ my $positive = shift;
Subroutine num2cat_cardinal: called CC=27 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 2 my @ones = qw(zero un dos tres quatre cinc sis set vuit nou);
36 2 my @teens = qw(deu onze dotze tretze catorze quinze setze disset divuit dinou);
37 2 my @tens = qw(_ _ vint trenta quaranta cinquanta seixanta setanta vuitanta noranta);
38  
39 2 ▶ return $ones[$positive] if $positive >= 0 && $positive <= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $positive >= 0 and $positive <= 9 2 0 2
Condition33%1/3
$positive >= 0 and $positive <= 9
!ll&&!rl&&r
002
MC/DC0%0/2
$positive >= 0 and $positive <= 9
$positive >= 0 $positive <= 9
Truth table33%1/3
A and B
A= $positive >= 0B= $positive <= 9
ABresult
0X0
100
111
40 0 ▶ return $teens[$positive - 10] if $positive >= 10 && $positive <= 19;
Branch: 1 branch
BranchTrueFalseTotal
if $positive >= 10 and $positive <= 19 0 0 0
Condition0%0/3
$positive >= 10 and $positive <= 19
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 10 and $positive <= 19
$positive >= 10 $positive <= 19
Truth table0%0/3
A and B
A= $positive >= 10B= $positive <= 19
ABresult
0X0
100
111
41  
42 0 ▶ if ($positive >= 20 && $positive <= 29) {
Branch: 1 branch
BranchTrueFalseTotal
if ($positive >= 20 and $positive <= 29) 0 0 0
Condition0%0/3
$positive >= 20 and $positive <= 29
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 20 and $positive <= 29
$positive >= 20 $positive <= 29
Truth table0%0/3
A and B
A= $positive >= 20B= $positive <= 29
ABresult
0X0
100
111
43 0 ▶ return 'vint' if $positive == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $positive == 20 0 0 0
44 0 return 'vint-i-' . $ones[$positive - 20];
45 }
46  
47 0 my $out;
48  
49 0 ▶ if ($positive >= 30 && $positive <= 99) {
Branch: 1 branch
BranchTrueFalseTotal
if ($positive >= 30 and $positive <= 99) 0 0 0
Condition0%0/3
$positive >= 30 and $positive <= 99
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 30 and $positive <= 99
$positive >= 30 $positive <= 99
Truth table0%0/3
A and B
A= $positive >= 30B= $positive <= 99
ABresult
0X0
100
111
50 0 my $ten_idx = int($positive / 10);
51 0 my $remain = $positive % 10;
52  
53 0 $out = $tens[$ten_idx];
54 0 ▶ $out .= '-' . $ones[$remain] if $remain;
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
55 0 return $out;
56 }
57  
58 0 ▶ if ($positive >= 100 && $positive <= 999) {
Branch: 1 branch
BranchTrueFalseTotal
if ($positive >= 100 and $positive <= 999) 0 0 0
Condition0%0/3
$positive >= 100 and $positive <= 999
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 100 and $positive <= 999
$positive >= 100 $positive <= 999
Truth table0%0/3
A and B
A= $positive >= 100B= $positive <= 999
ABresult
0X0
100
111
59 0 my $hun_idx = int($positive / 100);
60 0 my $remain = $positive % 100;
61  
62 0 ▶ if ($hun_idx == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hun_idx == 1) { } 0 0 0
63 0 $out = 'cent';
64 }
65 else {
66 0 $out = $ones[$hun_idx] . '-cents';
67 }
68 0 ▶ $out .= ' ' . num2cat_cardinal($remain) if $remain;
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
69 0 return $out;
70 }
71  
72 0 ▶ if ($positive >= 1000 && $positive <= 999_999) {
Branch: 1 branch
BranchTrueFalseTotal
if ($positive >= 1000 and $positive <= 999999) 0 0 0
Condition0%0/3
$positive >= 1000 and $positive <= 999999
!ll&&!rl&&r
000
MC/DC0%0/2
$positive >= 1000 and $positive <= 999999
$positive >= 1000 $positive <= 999999
Truth table0%0/3
A and B
A= $positive >= 1000B= $positive <= 999999
ABresult
0X0
100
111
73 0 my $tho_idx = int($positive / 1000);
74 0 my $remain = $positive % 1000;
75  
76 0 ▶ if ($tho_idx == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tho_idx == 1) { } 0 0 0
77 0 $out = 'mil';
78 }
79 else {
80 0 $out = num2cat_cardinal($tho_idx) . ' mil';
81 }
82 0 ▶ $out .= ' ' . num2cat_cardinal($remain) if $remain;
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
83 0 return $out;
84 }
85  
86 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
87 0 my $mil_idx = int($positive / 1_000_000);
88 0 my $remain = $positive % 1_000_000;
89  
90 0 ▶ if ($mil_idx == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mil_idx == 1) { } 0 0 0
91 0 $out = 'un milió';
92 }
93 else {
94 0 $out = num2cat_cardinal($mil_idx) . ' milions';
95 }
96 0 ▶ $out .= ' ' . num2cat_cardinal($remain) if $remain;
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
97 0 return $out;
98 }
99  
100 0 return $out;
101 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 # }}}
104  
105  
106 # {{{ capabilities declare supported features
107  
108 sub capabilities {
109 return {
110 0 ▶ cardinal => 1,
Subroutine capabilities: not called CC=1 SCAR=6.9
Pod undocumented
111 ordinal => 0,
112 };
113 }
114  
115 # }}}
116 1 1;
117  
118 __END__
↑ Summary