Valid/Rule.pm

filter: Statementstmt 100% 63 / 63 Branchbran 87.5% 21 / 24 Conditioncond 88.8% 8 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 14 / 14 Podpod 100% 7 / 7 totaltotal 95.0% 116 / 122 CC 23 SCAR 16.8
CC
23
Cov
96%
new
9.0
is_valid
8.0
_prepare
5.0
CRAP 5.3
« Valid.pm ↑ Summary Valid/Filter/Kana.pm »
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
BranchTrueFalseTotal
if (length $c == 2 or $c eq 'j' or $c eq 'y') { } 4213 3937 8150
Condition100%6/6
length $c == 2 or $c eq "j" or $c eq "y"
l!l&&r!l&&!r
39053083937
length $c == 2 or $c eq "j"
l!l&&r!l&&!r
36652404245
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"
ABCresult
1XX1
01X1
0011
0000
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
l!l&&r!l&&!r
2065800
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
52  
53 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
54 2145 ▶ if ( @data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) 75 2070 2145
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
BranchTrueFalseTotal
unless $self->{"filters"}{"word"}->can($filter) 770 492 1262
65 492 ▶ unless ( $self->{filters}->{word}->$filter( $word_ref ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"filters"}{"word"}->$filter($word_ref)) 2 490 492
66 2 ▶ warn "$filter returned false" if $Verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $Verbose 0 2 2
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
BranchTrueFalseTotal
unless $self->{"filters"}{"kana"}->can($filter) 1187 1848 3035
78 1848 ▶ unless ( $self->{filters}->{kana}->$filter( \$kana ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"filters"}{"kana"}->$filter(\$kana)) 7 1841 1848
79 7 ▶ warn "$filter returned false" if $Verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $Verbose 0 7 7
80 7 return;
81 }
82 }
83  
84 795 ▶ my $ret = exists $self->{valid}->{$kana} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'valid'}{$kana} ? : 668 127 795
85 795 ▶ unless ( $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ret) 127 668 795
86 127 ▶ warn "$kana is not valid" if $Verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $Verbose 0 127 127
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
BranchTrueFalseTotal
@_ ? : 306 16 322
92  
93 4 1;
94  
95 __END__
« Valid.pm ↑ Summary Valid/Filter/Kana.pm »