blib/lib/Lingua/KOR/Num2Word.pm

filter: Statementstmt 50.9% 27 / 53 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 30.2% 42 / 139 CC 26 SCAR 59.4
CC
26
Cov
29%
num2kor_cardinal
496.7
capabilities
2.0
BEGIN
1.0
CRAP 380.1
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*-
2  
3 package Lingua::KOR::Num2Word;
4 # ABSTRACT: Number to word conversion in Korean
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 # {{{ num2kor_cardinal convert number to text
25  
26 sub num2kor_cardinal :Export {
27 2 ▶ my $positive = shift;
Subroutine num2kor_cardinal: called CC=26 SCAR=62.1
Pod documented
28  
29 2 ▶ croak 'You should specify a number from interval [0, 999_999_999_999]'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > '999999999999' 0 2 2
Condition33%3/9
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > '999999999999'
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 > '999999999999'
defined $positive $positive =~ /\A\d+\z/msux $positive < 0 $positive > '999999999999'
Truth table20%1/5
not(A && B) or C or D
A= defined $positiveB= $positive =~ /\A\d+\z/msuxC= $positive < 0D= $positive > '999999999999'
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_999;
34  
35 2 my @digits = ('영', '일', '이', '삼', '사', '오', '육', '칠', '팔', '구');
36  
37 2 ▶ return $digits[$positive] if ($positive >= 0 && $positive <= 9); # 0 .. 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
38 0 ▶ return '십' if ($positive == 10); # 10
Branch: 1 branch
BranchTrueFalseTotal
if $positive == 10 0 0 0
39  
40 0 my $out; # string for return value construction
41 my $one_idx; # index for digits array
42 0 my $remain; # remainder
43  
44 0 ▶ if ($positive > 10 && $positive < 100) { # 11 .. 99
Branch: 5 branches
BranchTrueFalseTotal
if ($positive > 10 and $positive < 100) { } 0 0 0
elsif ($positive > 99 and $positive < 1000) { } 0 0 0
elsif ($positive > 999 and $positive < 10000) { } 0 0 0
elsif ($positive > 9999 and $positive < 100000000) { } 0 0 0
elsif ($positive > 99999999 and $positive < 1000000000000) { } 0 0 0
Condition0%0/3
$positive > 10 and $positive < 100
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 10 and $positive < 100
$positive > 10 $positive < 100
Truth table0%0/3
A and B
A= $positive > 10B= $positive < 100
ABresult
0X0
100
111
45 0 $one_idx = int ($positive / 10);
46 0 $remain = $positive % 10;
47  
48 0 ▶ $out = $one_idx > 1 ? "$digits[$one_idx]십" : '십';
Branch: 1 branch
BranchTrueFalseTotal
$one_idx > 1 ? : 0 0 0
49 0 ▶ $out .= $remain ? $digits[$remain] : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
50 }
51 ▶ 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
52 0 $one_idx = int ($positive / 100);
53 0 $remain = $positive % 100;
54  
55 0 ▶ $out = $one_idx > 1 ? "$digits[$one_idx]백" : '백';
Branch: 1 branch
BranchTrueFalseTotal
$one_idx > 1 ? : 0 0 0
56 0 ▶ $out .= $remain ? num2kor_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
57 }
58 ▶ elsif ($positive > 999 && $positive < 10_000) { # 1000 .. 9999
Condition0%0/3
$positive > 999 and $positive < 10000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 999 and $positive < 10000
$positive > 999 $positive < 10000
Truth table0%0/3
A and B
A= $positive > 999B= $positive < 10000
ABresult
0X0
100
111
59 0 $one_idx = int ($positive / 1000);
60 0 $remain = $positive % 1000;
61  
62 0 ▶ $out = $one_idx > 1 ? "$digits[$one_idx]천" : '천';
Branch: 1 branch
BranchTrueFalseTotal
$one_idx > 1 ? : 0 0 0
63 0 ▶ $out .= $remain ? num2kor_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
64 }
65 ▶ elsif ($positive > 9_999 && $positive < 100_000_000) { # 10000 .. 99_999_999
Condition0%0/3
$positive > 9999 and $positive < 100000000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 9999 and $positive < 100000000
$positive > 9999 $positive < 100000000
Truth table0%0/3
A and B
A= $positive > 9999B= $positive < 100000000
ABresult
0X0
100
111
66 0 $one_idx = int ($positive / 10000);
67 0 $remain = $positive % 10000;
68  
69 0 $out = num2kor_cardinal($one_idx) . '만';
70 0 ▶ $out .= $remain ? num2kor_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
71 }
72 ▶ elsif ($positive > 99_999_999
Condition0%0/3
$positive > 99999999 and $positive < '1000000000000'
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 99999999 and $positive < '1000000000000'
$positive > 99999999 $positive < '1000000000000'
Truth table0%0/3
A and B
A= $positive > 99999999B= $positive < '1000000000000'
ABresult
0X0
100
111
73 && $positive < 1_000_000_000_000) { # 100_000_000 .. 999_999_999_999
74 0 $one_idx = int ($positive / 100_000_000);
75 0 $remain = $positive % 100_000_000;
76  
77 0 $out = num2kor_cardinal($one_idx) . '억';
78 0 ▶ $out .= $remain ? num2kor_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
79 }
80  
81 0 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