blib/lib/Lingua/SQI/Num2Word.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 95.8% 23 / 24 Conditioncond 66.6% 18 / 27 MC/DCmcdc 43.7% 7 / 16 Subroutinesub 88.8% 8 / 9 Podpod 50.0% 1 / 2 totaltotal 82.9% 107 / 129 CC 22 SCAR 28.4
CC
22
Cov
89%
num2sqi_cardinal
23.0
capabilities
2.0
BEGIN
1.0
CRAP 17.2
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*-
2  
3 package Lingua::SQI::Num2Word;
4 # ABSTRACT: Number to word conversion in Albanian
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 # {{{ num2sqi_cardinal convert number to text
25  
26 sub num2sqi_cardinal :Export {
27 35 ▶ my $positive = shift;
Subroutine num2sqi_cardinal: called CC=22 SCAR=31.4
Pod documented
28  
29 35 ▶ 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 1 33 34
Condition77%7/9
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999
l!l&&r!l&&!r
1133
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0
l!l&&r!l&&!r
1034
defined $positive && $positive =~ /\A\d+\z/msux
!ll&&!rl&&r
1034
MC/DC50%2/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 table60%3/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 33 my @ones = qw(zero një dy tre katër pesë gjashtë shtatë tetë nëntë);
36 33 my @teens = qw(
37 dhjetë njëmbëdhjetë dymbëdhjetë trembëdhjetë katërmbëdhjetë
38 pesëmbëdhjetë gjashtëmbëdhjetë shtatëmbëdhjetë tetëmbëdhjetë nëntëmbëdhjetë
39 );
40 33 my @tens = qw(
41 _invalid _invalid njëzet tridhjetë dyzet pesëdhjetë
42 gjashtëdhjetë shtatëdhjetë tetëdhjetë nëntëdhjetë
43 );
44  
45 33 ▶ return $ones[$positive] if ($positive >= 0 && $positive < 10);
Branch: 1 branch
BranchTrueFalseTotal
if $positive >= 0 and $positive < 10 9 24 33
Condition66%2/3
$positive >= 0 and $positive < 10
!ll&&!rl&&r
0249
MC/DC50%1/2
$positive >= 0 and $positive < 10
$positive >= 0 $positive < 10
Truth table66%2/3
A and B
A= $positive >= 0B= $positive < 10
ABresult
0X0
100
111
46 24 ▶ return $teens[$positive - 10] if ($positive >= 10 && $positive < 20);
Branch: 1 branch
BranchTrueFalseTotal
if $positive >= 10 and $positive < 20 3 21 24
Condition66%2/3
$positive >= 10 and $positive < 20
!ll&&!rl&&r
0213
MC/DC50%1/2
$positive >= 10 and $positive < 20
$positive >= 10 $positive < 20
Truth table66%2/3
A and B
A= $positive >= 10B= $positive < 20
ABresult
0X0
100
111
47  
48 21 my $out;
49 my $remain;
50  
51 21 ▶ if ($positive >= 20 && $positive < 100) { # 20 .. 99
Branch: 4 branches
BranchTrueFalseTotal
if ($positive >= 20 and $positive < 100) { } 8 13 21
elsif ($positive >= 100 and $positive < 1000) { } 6 7 13
elsif ($positive >= 1000 and $positive < 1000000) { } 4 3 7
elsif ($positive >= 1000000 and $positive < 1000000000) { } 3 0 3
Condition66%2/3
$positive >= 20 and $positive < 100
!ll&&!rl&&r
0138
MC/DC50%1/2
$positive >= 20 and $positive < 100
$positive >= 20 $positive < 100
Truth table66%2/3
A and B
A= $positive >= 20B= $positive < 100
ABresult
0X0
100
111
52 8 my $ten_idx = int($positive / 10);
53 8 $remain = $positive % 10;
54  
55 8 $out = $tens[$ten_idx];
56 8 ▶ $out .= ' e ' . $ones[$remain] if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 6 2 8
57 }
58 ▶ elsif ($positive >= 100 && $positive < 1000) { # 100 .. 999
Condition66%2/3
$positive >= 100 and $positive < 1000
!ll&&!rl&&r
076
MC/DC50%1/2
$positive >= 100 and $positive < 1000
$positive >= 100 $positive < 1000
Truth table66%2/3
A and B
A= $positive >= 100B= $positive < 1000
ABresult
0X0
100
111
59 6 my $hund_idx = int($positive / 100);
60 6 $remain = $positive % 100;
61  
62 6 $out = $ones[$hund_idx] . 'qind';
63 6 ▶ $out .= ' e ' . num2sqi_cardinal($remain) if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 4 2 6
64 }
65 ▶ elsif ($positive >= 1000 && $positive < 1_000_000) { # 1000 .. 999_999
Condition66%2/3
$positive >= 1000 and $positive < 1000000
!ll&&!rl&&r
034
MC/DC50%1/2
$positive >= 1000 and $positive < 1000000
$positive >= 1000 $positive < 1000000
Truth table66%2/3
A and B
A= $positive >= 1000B= $positive < 1000000
ABresult
0X0
100
111
66 4 my $kilo_idx = int($positive / 1000);
67 4 $remain = $positive % 1000;
68  
69 4 $out = num2sqi_cardinal($kilo_idx) . ' mijë';
70 4 ▶ $out .= ' e ' . num2sqi_cardinal($remain) if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 2 2 4
71 }
72 ▶ elsif ($positive >= 1_000_000 && $positive < 1_000_000_000) { # 1_000_000 .. 999_999_999
Condition33%1/3
$positive >= 1000000 and $positive < 1000000000
!ll&&!rl&&r
003
MC/DC0%0/2
$positive >= 1000000 and $positive < 1000000000
$positive >= 1000000 $positive < 1000000000
Truth table33%1/3
A and B
A= $positive >= 1000000B= $positive < 1000000000
ABresult
0X0
100
111
73 3 my $mega_idx = int($positive / 1_000_000);
74 3 $remain = $positive % 1_000_000;
75  
76 3 $out = num2sqi_cardinal($mega_idx);
77 3 ▶ $out .= $mega_idx == 1 ? ' milion' : ' milionë';
Branch: 1 branch
BranchTrueFalseTotal
$mega_idx == 1 ? : 1 2 3
78 3 ▶ $out .= ' e ' . num2sqi_cardinal($remain) if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 1 2 3
79 }
80  
81 21 return $out;
82 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 # }}}
85  
86  
87 # {{{ capabilities declare supported features
88  
89 sub capabilities {
90 return {
91 0 ▶ cardinal => 1,
Subroutine capabilities: not called CC=1 SCAR=6.9
Pod undocumented
92 ordinal => 0,
93 };
94 }
95  
96 # }}}
97 1 1;
98  
99 __END__
↑ Summary