| 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
| |||||||||||||||||||||||||||||
| 33 | 88 | ▶ | return $WORDS{NaN} if $number eq 'NaN'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 87 | ▶ | if ($number =~ m/^ ( [-+] )? inf $/ix) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 36 | # infinity | ||||||||||||||||||||||||||||
| 37 | 3 | ▶ | push @names, $1 ? $WORDS{$1} : (), $WORDS{inf}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$WORDS{$sign} || ()
MC/DC50%1/2
$WORDS{$sign} || ()
$WORDS{$sign}
()
Truth table66%2/3
A || B
A= $WORDS{$sign}B= ()
| |||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # fraction | ||||||||||||||||||||||||||||
| 49 | 77 | ▶ | if (defined $frac && $frac ne $EMPTY_STR) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $frac and $frac ne $EMPTY_STR
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 68 | 25 | return $name . $ORDINAL_SUFFIX; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 3 | 1; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||