| 1 | package Lingua::JA::Romaji::Valid::Rule; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Lingua::JA::Romaji::Valid::Filter::Word; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Lingua::JA::Romaji::Valid::Filter::Kana; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | my $Verbose; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 308 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 308 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 308 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 308 | my %valid = ( a => 1, e => 1, i => 1, o => 1, u => 1, n => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 308 | foreach my $c ( $self->valid_consonants ) { | |||||||||||||||||||||||||||||||||||||||||
| 16 | 8150 | ▶ | if ( length $c == 2 or $c eq 'j' or $c eq 'y' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
length $c == 2 or $c eq "j" or $c eq "y"
length $c == 2 or $c eq "j"
MC/DC100%3/3
length $c == 2 or $c eq "j" or $c eq "y"
length $c == 2
$c eq "j"
$c eq "y"
Truth table100%4/4
A or B or C
A= length $c == 2B= $c eq "j"C= $c eq "y"
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 4213 | foreach my $v ( qw( a o u ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 18 | 12639 | $valid{ "$c$v" } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 3937 | foreach my $v ( qw( a e i o u ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 23 | 19685 | $valid{ "$c$v" } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 308 | foreach my $item ( $self->should_delete ) { | |||||||||||||||||||||||||||||||||||||||||
| 28 | 1160 | delete $valid{$item}; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 308 | foreach my $item ( $self->should_add ) { | |||||||||||||||||||||||||||||||||||||||||
| 31 | 2759 | $valid{$item} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 308 | $self->{valid} = \%valid; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | $self->{filters} = { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 308 | word => Lingua::JA::Romaji::Valid::Filter::Word->new, | |||||||||||||||||||||||||||||||||||||||||
| 38 | kana => Lingua::JA::Romaji::Valid::Filter::Kana->new, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 308 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 328 | ▶ | sub valid_consonants { shift->_value( valid_consonants => @_ ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
valid_consonants: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 328 | ▶ | sub should_delete { shift->_value( should_delete => @_ ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
should_delete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 328 | ▶ | sub should_add { shift->_value( should_add => @_ ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
should_add: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1161 | ▶ | sub filters { shift->_value( filters => @_ ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 2145 | ▶ | sub _value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 2145 | my ($self, $name, @data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 2145 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 2145 | ▶ | if ( @data ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 75 | @{ "$class\::$name" } = @data; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 2145 | @{ "$class\::$name" }; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 339 | ▶ | sub _prepare { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prepare: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 339 | my ($self, $word_ref, @extra_filters) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 339 | foreach my $filter ( $self->filters, @extra_filters ) { | |||||||||||||||||||||||||||||||||||||||||
| 64 | 1262 | ▶ | next unless $self->{filters}->{word}->can( $filter ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 492 | ▶ | unless ( $self->{filters}->{word}->$filter( $word_ref ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | warn "$filter returned false" if $Verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 337 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 802 | ▶ | sub is_valid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 802 | my ($self, $kana, @extra_filters) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 802 | foreach my $filter ( $self->filters, @extra_filters ) { | |||||||||||||||||||||||||||||||||||||||||
| 77 | 3035 | ▶ | next unless $self->{filters}->{kana}->can( $filter ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 1848 | ▶ | unless ( $self->{filters}->{kana}->$filter( \$kana ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | ▶ | warn "$filter returned false" if $Verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 795 | ▶ | my $ret = exists $self->{valid}->{$kana} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 795 | ▶ | unless ( $ret ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 127 | ▶ | warn "$kana is not valid" if $Verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 795 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 322 | ▶ | sub verbose { shift; @_ ? $Verbose = shift : $Verbose } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verbose: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||||||||||||||||