JBO/Numbers.pm

filter: Statementstmt 100% 43 / 43 Branchbran 87.5% 14 / 16 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 94.9% 75 / 79 CC 11 SCAR 18.1
CC
11
Cov
95%
num2jbo
10.0
num2jbo_ordinal
2.0
BEGIN
1.0
CRAP 6.1
« EO/Numbers.pm ↑ Summary TokiPona/Numbers.pm »
1 package Lingua::JBO::Numbers;
2  
3 3 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Regexp::Common qw( number );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 our @EXPORT_OK = qw( num2jbo num2jbo_ordinal );
11 3 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
12  
13 3 our $VERSION = '0.03';
14  
15 3 Readonly my $EMPTY_STR => q{};
16 3 Readonly my $ORDINAL_SUFFIX => q{moi};
17  
18 3 Readonly my @NAMES => qw< no pa re ci vo mu xa ze bi so >;
19 3 Readonly my %WORDS => (
20 '.' => "pi",
21 ',' => "ki'o",
22 '-' => "ni'u",
23 '+' => "ma'u",
24 inf => "ci'i",
25 NaN => "na namcu",
26 );
27  
28 89 ▶sub num2jbo {
Subroutine num2jbo: called CC=10 SCAR=23.0
Pod documented
29 89 my ($number) = @_;
30 89 my @names;
31  
32 89 ▶ return unless defined $number;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 1 88 89
33 88 ▶ return $WORDS{NaN} if $number eq 'NaN';
Branch: 1 branch
BranchTrueFalseTotal
if $number eq "NaN" 1 87 88
34  
35 87 ▶ if ($number =~ m/^ ( [-+] )? inf $/ix) {
Branch: 2 branches
BranchTrueFalseTotal
if ($number =~ /^ ( [-+] )? inf $/xi) { } 3 84 87
elsif ($number =~ /^ $Lingua::JBO::Numbers::RE{'num'}{'real'}{'-keep'} $/x) { } 77 7 84
36 # infinity
37 3 ▶ push @names, $1 ? $WORDS{$1} : (), $WORDS{inf};
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 2 1 3
38 }
39 elsif ($number =~ m/^ $RE{num}{real}{-keep} $/x) {
40 77 my ($sign, $int, $frac) = ($2, $4, $6);
41  
42 # sign and integer
43 push @names, (
44 $WORDS{$sign} || (),
45 77 ▶ map { $NAMES[$_] } split $EMPTY_STR, defined $int ? $int : $EMPTY_STR,
Branch: 1 branch
BranchTrueFalseTotal
defined $int ? : 77 0 77
Condition66%2/3
$WORDS{$sign} || ()
l!l&&r!l&&!r
11066
MC/DC50%1/2
$WORDS{$sign} || ()
$WORDS{$sign} ()
Truth table66%2/3
A || B
A= $WORDS{$sign}B= ()
ABresult
1X1
011
000
46 );
47  
48 # fraction
49 77 ▶ if (defined $frac && $frac ne $EMPTY_STR) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $frac and $frac ne $EMPTY_STR) 14 63 77
Condition100%3/3
defined $frac and $frac ne $EMPTY_STR
!ll&&!rl&&r
61214
MC/DC100%2/2
defined $frac and $frac ne $EMPTY_STR
defined $frac $frac ne $EMPTY_STR
Truth table100%3/3
A and B
A= defined $fracB= $frac ne $EMPTY_STR
ABresult
0X0
100
111
50 push @names, (
51 $WORDS{'.'},
52 14 map { $NAMES[$_] } split $EMPTY_STR, $frac,
53 );
54 }
55 }
56 else {
57 7 return;
58 }
59  
60 80 return join $EMPTY_STR, @names;
61 }
62  
63 25 ▶sub num2jbo_ordinal {
Subroutine num2jbo_ordinal: called CC=2 SCAR=7.0
Pod documented
64 25 my ($number) = @_;
65 25 my $name = num2jbo($number);
66  
67 25 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 25 25
68 25 return $name . $ORDINAL_SUFFIX;
69 }
70  
71 3 1;
72  
73 __END__
« EO/Numbers.pm ↑ Summary TokiPona/Numbers.pm »