blib/lib/String/Equivalence/Amharic.pm

filter: Statementstmt 82.6% 95 / 115 Branchbran 52.6% 20 / 38 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.2% 13 / 16 Podpod 83.3% 5 / 6 totaltotal 74.4% 134 / 180 CC 26 SCAR 21.6
CC
26
Cov
74%
downgrade
20.9
isReducible
6.0
hasEquivalence
6.0
CRAP 8.6
↑ Summary
1 package String::Equivalence::Amharic;
2  
3 # If either of these next two lines are inside
4 # the BEGIN block the package will break.
5 #
6 2 binmode(STDOUT, ":utf8");
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Regexp::Ethiopic::Amharic qw(:forms overload setForm subForm %AmharicEquivalence);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 BEGIN
13 2 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶ use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶ use vars qw( $VERSION @EXPORT %HaMaps );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 $VERSION = "0.08";
18  
19 2 @EXPORT = qw( &downgrade &inflate &isEquivalentTo &isReducible &hasEquivalence );
20  
21 2 %HaMaps =(
22 ሐ => "ኀኃሀሃ",
23 ኀ => "ሐኃሀሃ",
24 ኃ => "ኀሐሀሃ",
25 ሓ => "ሐኀኃሀሃ",
26 ኻ => "ሀሃ",
27 ኍ => "ኁሁሑ"
28 );
29 }
30  
31  
32 sub new
33 2 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
34 2 bless ( {}, shift );
35 }
36  
37  
38 sub _downgradeMultiTarget
39 1 ▶{
Subroutine _downgradeMultiTarget: called CC=3 SCAR=11.0
40 1 my ( $list, $re, $from, $targets ) = @_;
41  
42 1 my @to = split ( //, $targets );
43 1 my @outList = ();
44  
45 1 foreach my $to (@to) {
46 4 my @newList;
47 4 ▶ for (my $i=0; $i < @{$list}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$list;}) 8 4 12
48 8 $newList[$i] = $list->[$i]; # copy old list
49 8 $newList[$i] =~ s/$from/$to/;
50 }
51 4 push ( @outList, @newList ); # add new keys to old keys
52 }
53 1 push ( @{$list}, @outList ); # add new keys to old keys
54 1 $$re =~ s/$from(?!\])/[$from$targets]/;
55 }
56  
57  
58 sub _downgrade
59 1 ▶{
Subroutine _downgrade: called CC=3 SCAR=11.0
60 1 my ( $list, $re, $from, $to ) = @_;
61  
62 1 ▶ unless ( $to ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($to) 1 0 1
63 1 $to = $from;
64 1 $to =~ tr/ሀሃሗሠ-ሧኣእኧቍኵጕቈኰጐቆኮጎዑዒዔዕዖፀ-ፆኹኺኼኽኾ/ሃሀኋሰ-ሷአእቁኩጉቆኮጎቈኰጐዕኡኢኤእኦጸ-ጾሁሂሄህሆ/;
65 }
66  
67 1 my @newList;
68 1 ▶ for (my $i=0; $i < @{$list}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$list;}) 1 1 2
69 1 $newList[$i] = $list->[$i]; # copy old list
70 1 $newList[$i] =~ s/$from/$to/;
71 }
72 1 push ( @{$list}, @newList ); # add new keys to old keys
73 1 $$re =~ s/$from(?!\])/[$from$to]/;
74 }
75  
76  
77 sub downgrade
78 1 ▶{
Subroutine downgrade: called CC=12 SCAR=30.4
Pod documented
79 1 my $self;
80  
81 1 ($self, $_) = @_;
82 1 ▶ $_ = $self unless ( ref($self) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 1 1
83  
84 1 my @list = ( $_ );
85 1 my $re = $_;
86 1 my @letters = split ( // );
87  
88 1 foreach ( @letters ) {
89 3 ▶ if ( /([#ሠፀ#]|[ሀሃሗኣእኧቍኵጕቈኰጐቆኮጎዑዒዔዕዖኹኺኼኽኾ])/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/([\x{1220}-\x{1227}\x{1340}-\x{1346}]|[\x{1200}\x{1203}\x{1217}\x{12a3}\x{12a5}\x{12a7}\x{124d}\x{12b5}\x{1315}\x{1248}\x{12b0}\x{1310}\x{1246}\x{12ae}\x{130e}\x{12d1}\x{12d2}\x{12d4}\x{12d5}\x{12d6}\x{12b9}\x{12ba}\x{12bc}\x{12bd}\x{12be}])/) 1 2 3
90 1 my $from = $1;
91 1 ▶ _downgrade ( \@list, \$re, $from )
Branch: 1 branch
BranchTrueFalseTotal
unless $from eq "\x{12a5}" and $re =~ /^\x{12a5}/ 1 0 1
Condition33%1/3
$from eq "\x{12a5}" and $re =~ /^\x{12a5}/
!ll&&!rl&&r
100
MC/DC0%0/2
$from eq "\x{12a5}" and $re =~ /^\x{12a5}/
$from eq "\x{12a5}" $re =~ /^\x{12a5}/
Truth table33%1/3
A and B
A= $from eq "\x{12a5}"B= $re =~ /^\x{12a5}/
ABresult
0X0
100
111
92 unless ( $from eq "እ" && $re =~ /^እ/ );
93 }
94 3 ▶ if ( /([ዓዐ])/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/([\x{12d3}\x{12d0}])/) 0 3 3
95 0 ▶ my $to = ( $1 eq "ዓ" ) ? "አዐ" : "አዓ" ;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq "\x{12d3}" ? : 0 0 0
96 0 _downgradeMultiTarget ( \@list, \$re, $1, $to );
97 }
98 3 ▶ if ( /([ሑሒሔሕሖኁኂኄኅኆ])/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/([\x{1211}\x{1212}\x{1214}\x{1215}\x{1216}\x{1281}\x{1282}\x{1284}\x{1285}\x{1286}])/) 0 3 3
99 0 my $from = $1;
100 0 ▶ my $compliment = ( $from =~ /[#ኀ#]/ ) ? "ሐ" : "ኀ" ;
Branch: 1 branch
BranchTrueFalseTotal
$from =~ /[\x{1280}-\x{1286}\x{1288}-\x{128d}]/ ? : 0 0 0
101 0 my $to = subForm ( $compliment, $from ).subForm ( 'ሀ', $from );
102 0 _downgradeMultiTarget ( \@list, \$re, $from, $to );
103 }
104 3 ▶ if ( /([ሐኀኃሓኻኍ])/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/([\x{1210}\x{1280}\x{1283}\x{1213}\x{12bb}\x{128d}])/) 1 2 3
105 1 my $to = $HaMaps{$1};
106 1 _downgradeMultiTarget ( \@list, \$re, $1, $to );
107 }
108 }
109  
110  
111 1 ▶ wantarray ? ( @list, $re ) : $list[$#list] ;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
112 }
113  
114  
115 sub isReducible
116 0 ▶{
Subroutine isReducible: not called CC=2 SCAR=17.9
Pod documented
117 0 my $self;
118  
119 0 ($self, $_) = @_;
120 0 ▶ $_ = $self unless ( ref($self) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
121  
122 0 /[#ሐኀሠዐፀ#]|[ቍኍኵጕቈኈኰጐ]/;
123  
124 }
125  
126  
127 sub hasEquivalence
128 0 ▶{
Subroutine hasEquivalence: not called CC=2 SCAR=17.9
Pod documented
129 0 my $self;
130  
131 0 ($self, $_) = @_;
132 0 ▶ $_ = $self unless ( ref($self) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
133  
134 0 /[=#ሀሠዐፀ#=]|[=ቍ=]|[=ኍ=]|[=ኵ=]|[=ጕ=]|[=ቈ=]|[=ኈ=]|[=ኰ=]|[=ጐ=]/;
135 }
136  
137  
138 sub _inflate
139 2 ▶{
Subroutine _inflate: called CC=4 SCAR=13.9
140 2 my ($re, @words);
141  
142 2 foreach (@_) {
143 3 $re = $_;
144 3 $re =~ s/\[(\w+)\]/<replace>/;
145  
146 3 my @letters = split ( //, $1 );
147 3 foreach ( @letters ) {
148 14 push ( @words,$re );
149 14 $words[ $#words ] =~ s/<replace>/$_/;
150 }
151  
152 }
153  
154 2 ▶ if ( $words[0] =~ /\[/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($words[0] =~ /\[/) 1 1 2
155 1 push ( @words, _inflate( @words ) );
156 1 @words = grep { !/\[/ } @words;
157 }
158
159 2 return @words;
160 }
161  
162  
163 sub inflate
164 1 ▶{
Subroutine inflate: called CC=5 SCAR=16.1
Pod documented
165 1 my $self;
166  
167 1 ($self, $_) = @_;
168 1 ▶ $_ = $self unless ( ref($self) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 1 1
169  
170 1 my @words = ( $_ );
171 1 my $re = $_;
172  
173 1 my @letters = split ( // );
174  
175 1 foreach ( @letters ) {
176 3 ▶ if ( $AmharicEquivalence{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($String::Equivalence::Amharic::AmharicEquivalence{$_}) 2 1 3
177 #
178 # these next 3 lines are here to skip over old Amharic
179 #
180 2 my $equiv = $AmharicEquivalence{$_};
181 2 $equiv =~ s/[#ኸ#]//g;
182 2 $re =~ s/$_/[$equiv]/g;
183 # $re =~ s/$_/[$AmharicEquivalence{$_}]/g;
184 }
185 }
186  
187 1 ▶ if ( $re =~ /\[/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re =~ /\[/) 1 0 1
188 1 push ( @words, _inflate( $re ) );
189 1 @words = grep { !/\[/ } @words;
190 1 push ( @words, $re );
191 }
192  
193 1 return @words;
194 }
195  
196  
197 sub isEquivalentTo
198 0 ▶{
Subroutine isEquivalentTo: not called CC=2 SCAR=17.9
Pod documented
199 0 my ($self, $a, $b) = @_;
200  
201 0 ▶ unless ( ref($self) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 0 0 0
202 0 $b = $a;
203 0 $a = $self;
204 }
205  
206 0 my @b = $self->inflate( $b );
207
208 0 ( $a =~ /^$b[$#b]$/ );
209 }
210  
211  
212 #########################################################
213 # Do not change this, Do not put anything below this.
214 # File must return "true" value at termination
215 2 1;
216 ##########################################################
217  
218 __END__
↑ Summary