blib/lib/Lingua/ISL/Num2Word.pm

filter: Statementstmt 47.6% 30 / 63 Branchbran 6.2% 2 / 32 Conditioncond 13.3% 4 / 30 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 80.0% 8 / 10 Podpod 66.6% 2 / 3 totaltotal 29.4% 46 / 156 CC 27 SCAR 56.8
CC
27
Cov
29%
num2isl_cardinal
420.7
num2isl_neuter
12.0
capabilities
2.0
CRAP 293.4
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*-
2  
3 package Lingua::ISL::Num2Word;
4 # ABSTRACT: Number to word conversion in Icelandic
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 # {{{ num2isl_cardinal convert number to text
25  
26 sub num2isl_cardinal :Export {
27 2 ▶ my $positive = shift;
Subroutine num2isl_cardinal: called CC=25 SCAR=60.4
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 # 0 .. 19: unique words
36 2 my @tokens1 = qw(núll einn tveir þrír fjórir fimm sex sjö átta níu
37 tíu ellefu tólf);
38 2 my @teens = qw(þrettán fjórtán fimmtán sextán sautján átján nítján);
39  
40 # tens
41 2 my @tokens2 = qw(tuttugu þrjátíu fjörutíu fimmtíu sextíu sjötíu áttatíu níutíu);
42  
43 # neuter forms for use with hundrað/þúsund (both neuter nouns)
44 2 my @neuter = qw(núll eitt tvö þrjú fjögur fimm sex sjö átta níu);
45  
46 2 ▶ return $tokens1[$positive] if ($positive >= 0 && $positive < 13); # 0 .. 12
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
47 0 ▶ return $teens[$positive - 13] if ($positive > 12 && $positive < 20); # 13 .. 19
Branch: 1 branch
BranchTrueFalseTotal
if $positive > 12 and $positive < 20 0 0 0
Condition0%0/3
$positive > 12 and $positive < 20
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 12 and $positive < 20
$positive > 12 $positive < 20
Truth table0%0/3
A and B
A= $positive > 12B= $positive < 20
ABresult
0X0
100
111
48  
49 0 my $out; # string for return value construction
50 my $one_idx; # index for tokens arrays
51 0 my $remain; # remainder
52  
53 0 ▶ if ($positive > 19 && $positive < 100) { # 20 .. 99
Branch: 4 branches
BranchTrueFalseTotal
if ($positive > 19 and $positive < 100) { } 0 0 0
elsif ($positive > 99 and $positive < 1000) { } 0 0 0
elsif ($positive > 999 and $positive < 1000000) { } 0 0 0
elsif ($positive > 999999 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
54 0 $one_idx = int ($positive / 10);
55 0 $remain = $positive % 10;
56  
57 0 $out = $tokens2[$one_idx - 2];
58 0 ▶ $out .= " og $tokens1[$remain]" if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
59 }
60 ▶ elsif ($positive > 99 && $positive < 1000) { # 100 .. 999
Condition0%0/3
$positive > 99 and $positive < 1000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 99 and $positive < 1000
$positive > 99 $positive < 1000
Truth table0%0/3
A and B
A= $positive > 99B= $positive < 1000
ABresult
0X0
100
111
61 0 $one_idx = int ($positive / 100);
62 0 $remain = $positive % 100;
63  
64 # hundrað is neuter: eitt hundrað, tvö hundruð, ...
65 0 ▶ if ($one_idx == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($one_idx == 1) { } 0 0 0
66 0 $out = 'hundrað';
67 }
68 else {
69 0 $out = "$neuter[$one_idx] hundruð";
70 }
71 0 ▶ $out .= $remain ? ' og ' . num2isl_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
72 }
73 ▶ elsif ($positive > 999 && $positive < 1_000_000) { # 1000 .. 999_999
Condition0%0/3
$positive > 999 and $positive < 1000000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 999 and $positive < 1000000
$positive > 999 $positive < 1000000
Truth table0%0/3
A and B
A= $positive > 999B= $positive < 1000000
ABresult
0X0
100
111
74 0 $one_idx = int ($positive / 1000);
75 0 $remain = $positive % 1000;
76  
77 # þúsund is neuter and invariable
78 0 ▶ if ($one_idx == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($one_idx == 1) { } 0 0 0
elsif ($one_idx < 5) { } 0 0 0
79 0 $out = 'þúsund';
80 }
81 elsif ($one_idx < 5) {
82 0 $out = num2isl_neuter($one_idx) . ' þúsund';
83 }
84 else {
85 0 $out = num2isl_cardinal($one_idx) . ' þúsund';
86 }
87 0 ▶ $out .= $remain ? ' og ' . num2isl_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
88 }
89 ▶ elsif ( $positive > 999_999
Condition0%0/3
$positive > 999999 and $positive < 1000000000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 999999 and $positive < 1000000000
$positive > 999999 $positive < 1000000000
Truth table0%0/3
A and B
A= $positive > 999999B= $positive < 1000000000
ABresult
0X0
100
111
90 && $positive < 1_000_000_000) { # 1_000_000 .. 999_999_999
91 0 $one_idx = int ($positive / 1000000);
92 0 $remain = $positive % 1000000;
93  
94 0 ▶ if ($one_idx == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($one_idx == 1) { } 0 0 0
95 0 $out = 'ein milljón';
96 }
97 else {
98 0 $out = num2isl_cardinal($one_idx) . ' milljónir';
99 }
100 0 ▶ $out .= $remain ? ' og ' . num2isl_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
101 }
102  
103 0 return $out;
104 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
105  
106 # }}}
107 # {{{ num2isl_neuter neuter form for small numbers
108  
109 sub num2isl_neuter {
110 0 ▶ my $n = shift;
Subroutine num2isl_neuter: not called CC=3 SCAR=24.8
Pod documented
111 0 my @neuter = qw(núll eitt tvö þrjú fjögur);
112 0 ▶ return $neuter[$n] if ($n >= 0 && $n <= 4);
Branch: 1 branch
BranchTrueFalseTotal
if $n >= 0 and $n <= 4 0 0 0
Condition0%0/3
$n >= 0 and $n <= 4
!ll&&!rl&&r
000
MC/DC0%0/2
$n >= 0 and $n <= 4
$n >= 0 $n <= 4
Truth table0%0/3
A and B
A= $n >= 0B= $n <= 4
ABresult
0X0
100
111
113 0 return num2isl_cardinal($n);
114 }
115  
116 # }}}
117  
118  
119 # {{{ capabilities declare supported features
120  
121 sub capabilities {
122 return {
123 0 ▶ cardinal => 1,
Subroutine capabilities: not called CC=1 SCAR=6.9
Pod undocumented
124 ordinal => 0,
125 };
126 }
127  
128 # }}}
129 1 1;
130  
131 __END__
↑ Summary