| 1 | package Lingua::JA::Yomi; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 2 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use File::Slurp qw/slurp/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 2 | ▶ | use utf8; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 2 | our $VERSION = '0.01'; | |||||||||||||
| 7 | |||||||||||||||
| 8 | 2 | has debug => ( | |||||||||||||
| 9 | is => 'rw', | ||||||||||||||
| 10 | isa => 'Int', | ||||||||||||||
| 11 | default => 0, | ||||||||||||||
| 12 | ); | ||||||||||||||
| 13 | has dic_file => ( | ||||||||||||||
| 14 | is => 'rw', | ||||||||||||||
| 15 | isa => 'Str', | ||||||||||||||
| 16 | 1 | ▶ | default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 1 | my $self = shift; | |||||||||||||
| 18 | 1 | my $file = __FILE__; | |||||||||||||
| 19 | 1 | $file =~ s{/[^/]+\.pm$}{/bep-eng.dic}; | |||||||||||||
| 20 | 1 | $file; | |||||||||||||
| 21 | }, | ||||||||||||||
| 22 | 2 | ); | |||||||||||||
| 23 | has dic => ( | ||||||||||||||
| 24 | is => 'rw', | ||||||||||||||
| 25 | isa => 'HashRef', | ||||||||||||||
| 26 | lazy => 1, | ||||||||||||||
| 27 | 1 | ▶ | default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 28 | 1 | my $self = shift; | |||||||||||||
| 29 | 1 | ▶ | open (my $fh, "<:encoding(utf8)", $self->dic_file) or die "$!"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | 1 | my @lines = <$fh>; # utf8 flagged | |||||||||||||
| 31 | 1 | close $fh; | |||||||||||||
| 32 | # '#' started rows are comments | ||||||||||||||
| 33 | my %kana_of = map { | ||||||||||||||
| 34 | 47248 | chomp; | |||||||||||||
| 35 | 47248 | my @pair = split(/ /, $_); | |||||||||||||
| 36 | 47248 | $pair[0] => $pair[1]; | |||||||||||||
| 37 | } grep { | ||||||||||||||
| 38 | 1 | substr($_,0,1) ne '#'; | |||||||||||||
| 39 | } @lines; | ||||||||||||||
| 40 | 1 | return \%kana_of; | |||||||||||||
| 41 | }, | ||||||||||||||
| 42 | 2 | ); | |||||||||||||
| 43 | |||||||||||||||
| 44 | # pass in utf8 flagged string | ||||||||||||||
| 45 | 7 | ▶ | sub convert { | ||||||||||||
|
Subroutine
convert: called CC=10 SCAR=24.1
Pod
documented
| |||||||||||||||
| 46 | 7 | my ($self, $roman, $remainder) = @_; | |||||||||||||
| 47 | 7 | ▶ | $remainder ||= ''; | ||||||||||||
|
Condition100%2/2
$remainder ||= ""
MC/DC100%1/1
$remainder ||= ""
$remainder
Truth table100%2/2
A
A= $remainder
| |||||||||||||||
| 48 | 7 | ▶ | print "[convert]roman: $roman remainder: $remainder\n" if $self->debug; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | |||||||||||||||
| 50 | 7 | ▶ | return if ! $roman; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | |||||||||||||||
| 52 | 7 | $roman = uc $roman; | |||||||||||||
| 53 | |||||||||||||||
| 54 | 7 | ▶ | if ( $roman =~ /^([^A-Z]+)(.*)/ ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 55 | # preserve symbols | ||||||||||||||
| 56 | 0 | ▶ | return $2 ? ( $1 . $self->convert($2) ) : $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | } | ||||||||||||||
| 58 | elsif ( exists $self->dic->{$roman} ) { | ||||||||||||||
| 59 | 2 | ▶ | print "[convert]found: $roman, ".Encode::encode('utf8',$self->dic->{$roman})."\n" if $self->debug; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | 2 | ▶ | if ( ! $remainder ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 61 | 1 | return $self->dic->{$roman}; | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | else { | ||||||||||||||
| 64 | 1 | return $self->dic->{$roman} . $self->convert( $remainder ); | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | } | ||||||||||||||
| 67 | else { | ||||||||||||||
| 68 | 5 | my $last_of_roman = chop( $roman ); | |||||||||||||
| 69 | 5 | ▶ | return $self->convert( $roman, $last_of_roman . ($remainder || '') ); | ||||||||||||
|
Condition100%2/2
$remainder || ''
MC/DC100%1/1
$remainder || ''
$remainder
Truth table100%2/2
A
A= $remainder
| |||||||||||||||
| 70 | } | ||||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 2 | 1; | |||||||||||||
| 74 | |||||||||||||||
| 75 | __END__ | ||||||||||||||