| 1 | package String::Koremutake; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = '0.30'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | my @phonemes = map { lc } qw{BA BE BI BO BU BY DA DE DI DO DU DY FA FE FI | |||||||||||||||||||||||||||
| 8 | FO FU FY GA GE GI GO GU GY HA HE HI HO HU HY JA JE JI JO JU JY KA KE | ||||||||||||||||||||||||||||
| 9 | KI KO KU KY LA LE LI LO LU LY MA ME MI MO MU MY NA NE NI NO NU NY PA | ||||||||||||||||||||||||||||
| 10 | PE PI PO PU PY RA RE RI RO RU RY SA SE SI SO SU SY TA TE TI TO TU TY | ||||||||||||||||||||||||||||
| 11 | VA VE VI VO VU VY BRA BRE BRI BRO BRU BRY DRA DRE DRI DRO DRU DRY FRA | ||||||||||||||||||||||||||||
| 12 | FRE FRI FRO FRU FRY GRA GRE GRI GRO GRU GRY PRA PRE PRI PRO PRU PRY | ||||||||||||||||||||||||||||
| 13 | STA STE STI STO STU STY TRA TRE}; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | my %phoneme_to_number; | |||||||||||||||||||||||||||
| 16 | my %number_to_phoneme; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | my $number = 0; | |||||||||||||||||||||||||||
| 19 | 2 | foreach my $phoneme (@phonemes) { | |||||||||||||||||||||||||||
| 20 | 256 | $phoneme_to_number{$phoneme} = $number; | |||||||||||||||||||||||||||
| 21 | 256 | $number_to_phoneme{$number} = $phoneme; | |||||||||||||||||||||||||||
| 22 | 256 | $number++; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 27 | 1 | my $self = {}; | |||||||||||||||||||||||||||
| 28 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 29 | 1 | return $self; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 15 | ▶ | sub _numbers_to_koremutake { | ||||||||||||||||||||||||||
|
Subroutine
_numbers_to_koremutake: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 33 | 15 | my($self, $numbers) = @_; | |||||||||||||||||||||||||||
| 34 | 15 | my $string; | |||||||||||||||||||||||||||
| 35 | 15 | foreach my $n (@$numbers) { | |||||||||||||||||||||||||||
| 36 | 30 | ▶ | throw Error::Simple("0 <= $n <= 127") unless (0 <= $n) && ($n <= 127); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
0 <= $n and $n <= 127
MC/DC100%2/2
0 <= $n and $n <= 127
0 <= $n
$n <= 127
Truth table100%3/3
A and B
A= 0 <= $nB= $n <= 127
| |||||||||||||||||||||||||||||
| 37 | 28 | $string .= $number_to_phoneme{$n}; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 13 | return $string; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 14 | ▶ | sub _koremutake_to_numbers { | ||||||||||||||||||||||||||
|
Subroutine
_koremutake_to_numbers: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 43 | 14 | my($self, $string) = @_; | |||||||||||||||||||||||||||
| 44 | 14 | my @numbers; | |||||||||||||||||||||||||||
| 45 | my $phoneme; | ||||||||||||||||||||||||||||
| 46 | 14 | my @chars = split //, $string; | |||||||||||||||||||||||||||
| 47 | 14 | ▶ | while (@chars) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 61 | $phoneme .= shift @chars; | |||||||||||||||||||||||||||
| 49 | 61 | ▶ | next unless $phoneme =~ /[aeiouy]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 29 | my $number = $phoneme_to_number{$phoneme}; | |||||||||||||||||||||||||||
| 51 | 29 | ▶ | throw Error::Simple("Phoneme $phoneme not valid") unless defined $number; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 28 | push @numbers, $number; | |||||||||||||||||||||||||||
| 53 | 28 | $phoneme = ""; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 13 | return \@numbers; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 14 | ▶ | sub integer_to_koremutake { | ||||||||||||||||||||||||||
|
Subroutine
integer_to_koremutake: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 14 | my($self, $integer) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 14 | ▶ | throw Error::Simple("No integer given") unless defined $integer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 13 | ▶ | throw Error::Simple('Negative numbers not acceptable') if $integer < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 12 | my @numbers; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 12 | ▶ | @numbers = (0) if $integer == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 12 | ▶ | while ($integer != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 22 | push @numbers, $integer % 128; | |||||||||||||||||||||||||||
| 70 | 22 | $integer = int($integer/128); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 12 | return $self->_numbers_to_koremutake([reverse @numbers]); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 13 | ▶ | sub koremutake_to_integer { | ||||||||||||||||||||||||||
|
Subroutine
koremutake_to_integer: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 13 | my($self, $string) = @_; | |||||||||||||||||||||||||||
| 77 | 13 | ▶ | throw Error::Simple("No koremutake string given") unless defined $string; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 12 | my $numbers = $self->_koremutake_to_numbers($string); | |||||||||||||||||||||||||||
| 80 | 12 | my $integer = 0; | |||||||||||||||||||||||||||
| 81 | 12 | ▶ | while (@$numbers) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 23 | my $n = shift @$numbers; | |||||||||||||||||||||||||||
| 83 | 23 | $integer = ($integer * 128) + $n; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 12 | return $integer; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 2 | 1; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||