blib/lib/Lingua/JA/Yomi.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 56.2% 9 / 16 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 88.5% 62 / 70 CC 11 SCAR 20.1
CC
11
Cov
87%
convert
11.2
__ANON__
2.0
BEGIN
1.0
CRAP 7.5
↑ Summary
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
BranchTrueFalseTotal
open my $fh, "<:encoding(utf8)", $self->dic_file or die "$!" 1 0 1
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 ||= ""
l!l
52
MC/DC100%1/1
$remainder ||= ""
$remainder
Truth table100%2/2
A
A= $remainder
Aresult
11
00
48 7 ▶ print "[convert]roman: $roman remainder: $remainder\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 7 7
49  
50 7 ▶ return if ! $roman;
Branch: 1 branch
BranchTrueFalseTotal
unless $roman 0 7 7
51  
52 7 $roman = uc $roman;
53  
54 7 ▶ if ( $roman =~ /^([^A-Z]+)(.*)/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($roman =~ /^([^A-Z]+)(.*)/) { } 0 7 7
elsif (exists $self->dic->{$roman}) { } 2 5 7
55 # preserve symbols
56 0 ▶ return $2 ? ( $1 . $self->convert($2) ) : $1;
Branch: 1 branch
BranchTrueFalseTotal
$2 ? : 0 0 0
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
BranchTrueFalseTotal
if $self->debug 0 2 2
60 2 ▶ if ( ! $remainder ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $remainder) { } 1 1 2
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 || ''
l!l
41
MC/DC100%1/1
$remainder || ''
$remainder
Truth table100%2/2
A
A= $remainder
Aresult
11
00
70 }
71 }
72  
73 2 1;
74  
75 __END__
↑ Summary