blib/lib/Lingua/EST/Num2Word.pm

filter: Statementstmt 49.0% 27 / 55 Branchbran 6.2% 2 / 32 Conditioncond 14.8% 4 / 27 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 88.8% 8 / 9 Podpod 50.0% 1 / 2 totaltotal 29.7% 42 / 141 CC 26 SCAR 59.5
CC
26
Cov
29%
num2est_cardinal
500.8
capabilities
2.0
BEGIN
1.0
CRAP 383.2
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*-
2  
3 package Lingua::EST::Num2Word;
4 # ABSTRACT: Number to word conversion in Estonian
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 # {{{ num2est_cardinal convert number to text
25  
26 sub num2est_cardinal :Export {
27 2 ▶ my $positive = shift;
Subroutine num2est_cardinal: called CC=26 SCAR=62.2
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(null üks kaks kolm neli viis kuus seitse kaheksa üheksa);
36  
37 2 ▶ return $ones[$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
38 0 ▶ return 'kümme' if ($positive == 10);
Branch: 1 branch
BranchTrueFalseTotal
if $positive == 10 0 0 0
39  
40 # 11-19: stem + teist
41 0 ▶ 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
42 0 my @teens = qw(üksteist kaksteist kolmteist neliteist viisteist
43 kuusteist seitseteist kaheksateist üheksateist);
44 0 return $teens[$positive - 11];
45 }
46  
47 0 my $out;
48 my $remain;
49  
50 0 my @tens_prefix = qw(. . kaks kolm neli viis kuus seitse kaheksa üheksa);
51  
52 0 ▶ if ($positive > 19 && $positive < 100) { # 20 .. 99
Branch: 5 branches
BranchTrueFalseTotal
if ($positive > 19 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 > 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
53 0 my $tens_idx = int($positive / 10);
54 0 $remain = $positive % 10;
55  
56 0 $out = $tens_prefix[$tens_idx] . 'kümmend';
57 0 ▶ $out .= ' ' . $ones[$remain] if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
58 }
59 elsif ($positive == 100) { # 100
60 0 $out = 'sada';
61 }
62 ▶ 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
63 0 my $hundreds = int($positive / 100);
64 0 $remain = $positive % 100;
65  
66 0 ▶ $out = $hundreds == 1 ? 'sada' : $ones[$hundreds] . 'sada';
Branch: 1 branch
BranchTrueFalseTotal
$hundreds == 1 ? : 0 0 0
67 0 ▶ $out .= ' ' . num2est_cardinal($remain) if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
68 }
69 ▶ 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
70 0 my $thousands = int($positive / 1000);
71 0 $remain = $positive % 1000;
72  
73 0 ▶ $out = $thousands == 1 ? 'tuhat' : num2est_cardinal($thousands) . ' tuhat';
Branch: 1 branch
BranchTrueFalseTotal
$thousands == 1 ? : 0 0 0
74 0 ▶ $out .= ' ' . num2est_cardinal($remain) if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
75 }
76 ▶ 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
77 0 my $millions = int($positive / 1_000_000);
78 0 $remain = $positive % 1_000_000;
79  
80 0 ▶ if ($millions == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($millions == 1) { } 0 0 0
81 0 $out = 'miljon';
82 }
83 else {
84 0 $out = num2est_cardinal($millions) . ' miljonit';
85 }
86 0 ▶ $out .= ' ' . num2est_cardinal($remain) if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 0 0 0
87 }
88  
89 0 return $out;
90 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 # }}}
93  
94  
95 # {{{ capabilities declare supported features
96  
97 sub capabilities {
98 return {
99 0 ▶ cardinal => 1,
Subroutine capabilities: not called CC=1 SCAR=6.9
Pod undocumented
100 ordinal => 0,
101 };
102 }
103  
104 # }}}
105 1 1;
106  
107 __END__
↑ Summary