blib/lib/Lingua/FAS/Num2Word.pm

filter: Statementstmt 57.6% 30 / 52 Branchbran 7.6% 2 / 26 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 88.8% 8 / 9 Podpod 50.0% 1 / 2 totaltotal 43.1% 44 / 102 CC 17 SCAR 47.6
CC
17
Cov
40%
num2fas_cardinal
170.3
capabilities
2.0
BEGIN
1.0
CRAP 116.2
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*-
2  
3 package Lingua::FAS::Num2Word;
4 # ABSTRACT: Number to word conversion in Persian
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 # {{{ num2fas_cardinal convert number to text
25  
26 sub num2fas_cardinal :Export {
27 2 ▶ my $positive = shift;
Subroutine num2fas_cardinal: called CC=17 SCAR=51.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 2 my @ones = ('صفر', 'یک', 'دو', 'سه', 'چهار', 'پنج', 'شش', 'هفت', 'هشت', 'نه');
36 2 my @teens = ('ده', 'یازده', 'دوازده', 'سیزده', 'چهارده', 'پانزده',
37 'شانزده', 'هفده', 'هجده', 'نوزده');
38 2 my @tens = ('بیست', 'سی', 'چهل', 'پنجاه', 'شصت', 'هفتاد', 'هشتاد', 'نود');
39 2 my @hundreds = ('صد', 'دویست', 'سیصد', 'چهارصد', 'پانصد',
40 'ششصد', 'هفتصد', 'هشتصد', 'نهصد');
41  
42 # 0 .. 9
43 2 ▶ return $ones[$positive] if $positive < 10;
Branch: 1 branch
BranchTrueFalseTotal
if $positive < 10 2 0 2
44  
45 # 10 .. 19
46 0 ▶ return $teens[$positive - 10] if $positive < 20;
Branch: 1 branch
BranchTrueFalseTotal
if $positive < 20 0 0 0
47  
48 # 20 .. 99
49 0 ▶ if ($positive < 100) {
Branch: 1 branch
BranchTrueFalseTotal
if ($positive < 100) 0 0 0
50 0 my $ten_idx = int($positive / 10) - 2;
51 0 my $remain = $positive % 10;
52  
53 0 ▶ return $tens[$ten_idx] if $remain == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $remain == 0 0 0 0
54 0 return $tens[$ten_idx] . ' و ' . $ones[$remain];
55 }
56  
57 0 my $out;
58 my $remain;
59  
60 # 100 .. 999
61 0 ▶ if ($positive < 1000) {
Branch: 3 branches
BranchTrueFalseTotal
if ($positive < 1000) { } 0 0 0
elsif ($positive < 1000000) { } 0 0 0
elsif ($positive < 1000000000) { } 0 0 0
62 0 my $hun_idx = int($positive / 100) - 1;
63 0 $remain = $positive % 100;
64  
65 0 $out = $hundreds[$hun_idx];
66 0 ▶ $out .= $remain ? ' و ' . num2fas_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
67 }
68 # 1000 .. 999_999
69 elsif ($positive < 1_000_000) {
70 0 my $tho_idx = int($positive / 1000);
71 0 $remain = $positive % 1000;
72  
73 0 ▶ $out = $tho_idx == 1 ? 'هزار' : num2fas_cardinal($tho_idx) . ' هزار';
Branch: 1 branch
BranchTrueFalseTotal
$tho_idx == 1 ? : 0 0 0
74 0 ▶ $out .= $remain ? ' و ' . num2fas_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
75 }
76 # 1_000_000 .. 999_999_999
77 elsif ($positive < 1_000_000_000) {
78 0 my $mil_idx = int($positive / 1_000_000);
79 0 $remain = $positive % 1_000_000;
80  
81 0 ▶ $out = $mil_idx == 1 ? 'یک میلیون' : num2fas_cardinal($mil_idx) . ' میلیون';
Branch: 1 branch
BranchTrueFalseTotal
$mil_idx == 1 ? : 0 0 0
82 0 ▶ $out .= $remain ? ' و ' . num2fas_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
83 }
84  
85 0 return $out;
86 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 # }}}
89  
90  
91 # {{{ capabilities declare supported features
92  
93 sub capabilities {
94 return {
95 0 ▶ cardinal => 1,
Subroutine capabilities: not called CC=1 SCAR=6.9
Pod undocumented
96 ordinal => 0,
97 };
98 }
99  
100 # }}}
101 1 1;
102  
103 __END__
↑ Summary