Ethiopic.pm

filter: Statementstmt 66.4% 87 / 131 Branchbran 42.3% 22 / 52 Conditioncond 40.0% 6 / 15 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 68.7% 11 / 16 Podpod 50.0% 4 / 8 totaltotal 57.1% 132 / 231 CC 38 SCAR 25.7
CC
38
Cov
58%
getForm
30.0
import
28.1
setForm
16.9
CRAP 13.1
↑ Summary Ethiopic/Amharic.pm »
1 package Regexp::Ethiopic;
2 1 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 BEGIN
6 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use vars qw($VERSION @EXPORT_OK %EXPORT_TAGS %EthiopicClasses
Subroutine BEGIN: called CC=1 SCAR=0.0
10 $ግዕዝ $ካዕብ $ሣልስ $ራብዕ $ኃምስ $ሳድስ $ሳብዕ
11 1 $ዘመደ_ግዕዝ $ዘመደ_ካዕብ $ዘመደ_ሣልስ $ዘመደ_ራብዕ $ዘመደ_ኃምስ);
12  
13  
14 1 $VERSION = "0.21";
15
16 1 @EXPORT_OK = qw(%EthiopicClasses &getForm &setForm &subForm &formatForms &isFamilyOf
17 $ግዕዝ $ካዕብ $ሣልስ $ራብዕ $ኃምስ $ሳድስ $ሳብዕ
18 $ዘመደ_ግዕዝ $ዘመደ_ካዕብ $ዘመደ_ሣልስ $ዘመደ_ራብዕ $ዘመደ_ኃምስ
19 );
20 1 %EXPORT_TAGS = ( forms => [qw(
21 $ግዕዝ $ካዕብ $ሣልስ $ራብዕ $ኃምስ $ሳድስ $ሳብዕ
22 $ዘመደ_ግዕዝ $ዘመደ_ካዕብ $ዘመደ_ሣልስ $ዘመደ_ራብዕ $ዘመደ_ኃምስ)],
23 utils => [qw(&getForm &setForm &subForm &formatForms &isFamilyOf)]
24 );
25  
26  
27 1 %EthiopicClasses =(
28 1 => "ሀለሐመሠረሰሸቀቐበቨተቸኀነኘአከኸወዐዘዠየደዸጀገጘጠጨጰጸፀፈፐ",
29 2 => "ሁሉሐሙሡሩሱሹቁቑቡቩቱቹኁኑኙኡኩኹዉዑዙዡዩዱዹጁጉጙጡጩጱጹፁፉፑ",
30 3 => "ሂሊሒሚሢሪሲሺቂቒቢቪቲቺኂኒኚኢኪኺዊዒዚዢዪዲዺጂጊጚጢጪጲጺፂፊፒ",
31 4 => "ሃላሓማሣራሳሻቃቓባቫታቻኃናኛኣካኻዋዓዛዣያዳዻጃጋጛጣጫጳጻፃፋፓ",
32 5 => "ሄሌሔሜሤሬሴሼቄቔቤቬቴቼኄኔኜኤኬኼዌዔዜዤዬዴዼጄጌጜጤጬጴጼፄፌፔ",
33 6 => "ህልሕምሥርስሽቅቕብቭትችኅንኝእክኽውዕዝዥይድዽጅግጝጥጭጵጽፅፍፕ",
34 7 => "ሆሎሖሞሦሮሶሾቆቖቦቮቶቾኆኖኞኦኮኾዎዖዞዦዮዶዾጆጎጞጦጮጶጾፆፎፖ",
35 8 => "ቈቘኈኰዀጐኧ",
36 9 => "ቍቝኍኵዅጕ",
37 10 => "ቊቚኊኲዂጒ",
38 11 => "ሗሏሟሧሯሷሿቋቛቧቯቷቿኋኗኟኳዃዟዧዷዿጇጓጧጯጷጿፏፗ",
39 12 => "ቌቜኌኴዄጔ",
40 ሀ => "ሀ-ሆ",
41 ለ => "ለ-ሏ",
42 ሐ => "ሐ-ሗ",
43 መ => "መ-ሟ",
44 ሠ => "ሠ-ሧ",
45 ረ => "ረ-ሯ",
46 ሰ => "ሰ-ሷ",
47 ሸ => "ሸ-ሿ",
48 ቀ => "ቀ-ቆቈ-ቍ",
49 ቐ => "ቐ-ቖቘ-ቝ",
50 በ => "በ-ቧ",
51 ቨ => "ቨ-ቯ",
52 ተ => "ተ-ቷ",
53 ቸ => "ቸ-ቿ",
54 ኀ => "ኀ-ኆኈ-ኍ",
55 ነ => "ነ-ኗ",
56 ኘ => "ኘ-ኟ",
57 አ => "አ-ኧ",
58 ከ => "ከ-ኮኰኲ-ኵ",
59 ኸ => "ኸ-ኾዀ-ዅ",
60 ወ => "ወ-ዎ",
61 ዐ => "ዐ-ዖ",
62 ዘ => "ዘ-ዟ",
63 ዠ => "ዠ-ዧ",
64 የ => "የ-ዮ",
65 ደ => "ደ-ዷ",
66 ዸ => "ዸ-ዿ",
67 ጀ => "ጀ-ጇ",
68 ገ => "ገ-ጎጐ-ጕ",
69 ጘ => "ጘ-ጞ",
70 ጠ => "ጠ-ጧ",
71 ጨ => "ጨ-ጯ",
72 ጰ => "ጰ-ጷ",
73 ጸ => "ጸ-ጿ",
74 ፀ => "ፀ-ፆ",
75 ፈ => "ፈ-ፏ",
76 ፐ => "ፐ-ፗ",
77 አኃዝ => "፩-፼"
78 );
79  
80 $EthiopicClasses{'ግዕዝ'}
81 = $EthiopicClasses{geez}
82 1 = $EthiopicClasses{1}
83 ;
84 $EthiopicClasses{'ካዕብ'}
85 = $EthiopicClasses{kaib}
86 1 = $EthiopicClasses{2}
87 ;
88 $EthiopicClasses{'ሣልስ'}
89 = $EthiopicClasses{salis}
90 1 = $EthiopicClasses{3}
91 ;
92 $EthiopicClasses{'ራብዕ'}
93 = $EthiopicClasses{rabi}
94 1 = $EthiopicClasses{4}
95 ;
96 $EthiopicClasses{'ኃምስ'}
97 = $EthiopicClasses{hamis}
98 1 = $EthiopicClasses{5}
99 ;
100 $EthiopicClasses{'ሳድስ'}
101 = $EthiopicClasses{sadis}
102 1 = $EthiopicClasses{6}
103 ;
104 $EthiopicClasses{'ሳብዕ'}
105 = $EthiopicClasses{sabi}
106 1 = $EthiopicClasses{7}
107 ;
108 $EthiopicClasses{'ዘመደ፡ግዕዝ'}
109 = $EthiopicClasses{'zemede:geez'}
110 1 = $EthiopicClasses{8}
111 ;
112 $EthiopicClasses{'ዘመደ፡ካዕብ'}
113 = $EthiopicClasses{'zemede:kaib'}
114 1 = $EthiopicClasses{9}
115 ;
116 $EthiopicClasses{'ዘመደ፡ሣልስ'}
117 = $EthiopicClasses{'zemede:salis'}
118 1 = $EthiopicClasses{10}
119 ;
120 $EthiopicClasses{'ዘመደ፡ራብዕ'}
121 = $EthiopicClasses{'zemede:rabi'}
122 1 = $EthiopicClasses{11}
123 ;
124 $EthiopicClasses{'ዘመደ፡ኃምስ'}
125 = $EthiopicClasses{'zemede:hamis'}
126 1 = $EthiopicClasses{12}
127 ;
128 $EthiopicClasses{'ahaz'}
129 1 = $EthiopicClasses{'አኃዝ'}
130 ;
131  
132 1 ($ግዕዝ, $ካዕብ, $ሣልስ, $ራብዕ, $ኃምስ, $ሳድስ, $ሳብዕ,
133 $ዘመደ_ግዕዝ, $ዘመደ_ካዕብ, $ዘመደ_ሣልስ, $ዘመደ_ራብዕ, $ዘመደ_ኃምስ) = (1 .. 12);
134  
135 }
136  
137 sub import
138 0 ▶{
Subroutine import: not called CC=6 SCAR=33.4
139  
140 0 my @args = ( shift ); # package
141 0 foreach (@_) {
142 0 ▶ if ( /overload/o ) {
Branch: 3 branches
BranchTrueFalseTotal
if (/overload/o) { } 0 0 0
elsif (/:forms/o) { } 0 0 0
elsif (/:utils/o) { } 0 0 0
143 1 ▶ use overload;
Subroutine BEGIN: called CC=1 SCAR=0.0
144 0 overload::constant 'qr' => \&getRe;
145 }
146 elsif ( /:forms/o ) {
147 0 Regexp::Ethiopic->export_to_level (1, $args[0], ':forms'); # this works too...
148 }
149 elsif ( /:utils/o ) {
150 0 Regexp::Ethiopic->export_to_level (1, $args[0], ':utils'); # this works too...
151 }
152 else {
153 0 push (@args, $_);
154 }
155 }
156 0 ▶ if ($#args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#args) 0 0 0
157 0 Regexp::Ethiopic->export_to_level (1, @args); # this works too...
158 }
159  
160 }
161  
162  
163 sub getForm
164 0 ▶{
Subroutine getForm: not called CC=5 SCAR=34.0
Pod documented
165 0 my ($ሆሄ) = @_;
166  
167 0 my $form = ord($ሆሄ)%8 + 1;
168  
169 0 ▶ if ( $form == 8 || $ሆሄ =~ /[ቋቛኋኳዃጓ]/o ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($form == 8 or $ሆሄ =~ /[\x{124b}\x{125b}\x{128b}\x{12b3}\x{12c3}\x{1313}]/o) { } 0 0 0
elsif ($ሆሄ =~ /[\x{124d}\x{125d}\x{128d}\x{12b5}\x{12c5}\x{1315}]/o) { } 0 0 0
elsif ($ሆሄ =~ /[\x{1248}\x{1258}\x{1288}\x{12b0}\x{12c0}\x{1310}\x{124a}\x{125a}\x{128a}\x{12b2}\x{12c2}\x{1312}\x{124c}\x{125c}\x{128c}\x{12b4}\x{12c4}\x{1314}]/o) { } 0 0 0
Condition0%0/3
$form == 8 or $ሆሄ =~ /[\x{124b}\x{125b}\x{128b}\x{12b3}\x{12c3}\x{1313}]/o
l!l&&r!l&&!r
000
MC/DC0%0/2
$form == 8 or $ሆሄ =~ /[\x{124b}\x{125b}\x{128b}\x{12b3}\x{12c3}\x{1313}]/o
$form == 8 $ሆሄ =~ /[\x{124b}\x{125b}\x{128b}\x{12b3}\x{12c3}\x{1313}]/o
Truth table0%0/3
A or B
A= $form == 8B= $ሆሄ =~ /[\x{124b}\x{125b}\x{128b}\x{12b3}\x{12c3}\x{1313}]/o
ABresult
1X1
011
000
170 0 $form = 11;
171 }
172 elsif ( $ሆሄ =~ /[ቍቝኍኵዅጕ]/o ) {
173 0 $form = 9;
174 }
175 elsif ( $ሆሄ =~ /[ቈቘኈኰዀጐቊቚኊኲዂጒቌቜኌኴዄጔ]/o ) {
176 0 $form += 7;
177 }
178  
179 0 $form;
180 }
181  
182  
183 sub setForm
184 4 ▶{
Subroutine setForm: called CC=8 SCAR=28.2
Pod documented
185 4 my ($ሆሄ, $form) = @_;
186  
187 4 ▶ if ( $ሆሄ =~ /[ኈ-ኍቈ-ቍቘ-ቝኰ-ኵዀ-ዅጐ-ጕ]/o ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ሆሄ =~ /[\x{1288}-\x{128d}\x{1248}-\x{124d}\x{1258}-\x{125d}\x{12b0}-\x{12b5}\x{12c0}-\x{12c5}\x{1310}-\x{1315}]/o) 0 4 4
188 0 $ሆሄ =~ s/[ኈ-ኍ]/ኅ/o;
189 0 $ሆሄ =~ s/[ቈ-ቍ]/ቀ/o;
190 0 $ሆሄ =~ s/[ቘ-ቝ]/ቐ/o;
191 0 $ሆሄ =~ s/[ኰ-ኵ]/ከ/o;
192 0 $ሆሄ =~ s/[ዀ-ዅ]/ኸ/o;
193 0 $ሆሄ =~ s/[ጐ-ጕ]/ገ/o;
194 }
195 4 ▶ $form = 4 if ( $ሆሄ =~ /[ቋቛኋኳዃጓ]/o );
Branch: 1 branch
BranchTrueFalseTotal
if $ሆሄ =~ /[\x{124b}\x{125b}\x{128b}\x{12b3}\x{12c3}\x{1313}]/o 0 4 4
196 4 ▶ $form -= 7 if ( $form == 8 || $form == 10 || $form == 12 );
Branch: 1 branch
BranchTrueFalseTotal
if $form == 8 or $form == 10 or $form == 12 0 4 4
Condition33%2/6
$form == 8 or $form == 10 or $form == 12
l!l&&r!l&&!r
004
$form == 8 or $form == 10
l!l&&r!l&&!r
004
MC/DC0%0/3
$form == 8 or $form == 10 or $form == 12
$form == 8 $form == 10 $form == 12
Truth table25%1/4
A or B or C
A= $form == 8B= $form == 10C= $form == 12
ABCresult
1XX1
01X1
0011
0000
197 4 ▶ $form = 8 if ( $form == 11 );
Branch: 1 branch
BranchTrueFalseTotal
if $form == 11 0 4 4
198 4 ▶ $form = 6 if ( $form == 9 );
Branch: 1 branch
BranchTrueFalseTotal
if $form == 9 0 4 4
199  
200 4 chr ( ord($ሆሄ) - ord($ሆሄ)%8 + $form-1 );
201 }
202  
203  
204 sub subForm
205 0 ▶{
Subroutine subForm: not called CC=1 SCAR=6.9
Pod documented
206 0 my ($set, $get) = @_;
207  
208 # e.g. s/([=#ሀ#=])/subForm($1, ሀ)/eg;
209 0 setForm ( $set, getForm ( $get ) );
210 }
211  
212  
213 sub isFamilyOf
214 0 ▶{
Subroutine isFamilyOf: not called CC=1 SCAR=6.9
Pod undocumented
215 0 my ($a,$b) = @_;
216  
217 0 my $gez = setForm($a,1);
218 0 my $re = getRe( "[#$gez#]" );
219 0 ( $b =~ /$re/ );
220 }
221  
222  
223 sub formatForms
224 0 ▶{
Subroutine formatForms: not called CC=3 SCAR=24.8
Pod documented
225 0 my ($format, $string) = @_;
226  
227 0 my @chars = split ( //, $string );
228  
229 0 ▶ if ( @chars != ($format =~ s/%/%/g) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@chars != $format =~ s/%/%/g) 0 0 0
230 0 $format =~ s/\p{Ethiopic}//g;
231 0 warn ( "\"$string\" is of different length from $format." );
232 0 return;
233 }
234  
235 0 foreach (@chars) {
236 0 $format =~ s/%(\d+)/setForm($_, $1)/e;
237 }
238  
239 0 $format;
240 }
241  
242  
243 sub handleChars
244 4 ▶{
Subroutine handleChars: called CC=10 SCAR=23.3
Pod undocumented
245 4 my ($chars,$form) = @_;
246  
247 4 ▶ return ( $EthiopicClasses{$form} ) if ( $chars eq "all" );
Branch: 1 branch
BranchTrueFalseTotal
if $chars eq "all" 0 4 4
248  
249 4 my $re;
250  
251 4 $chars =~ s/(\w)(?=\w)/$1,/og;
252 4 my @Chars = split ( /,/, $chars );
253 4 foreach (@Chars) {
254 8 ▶ if ( /(\w)-(\w)/o ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(\w)-(\w)/o) { } 4 4 8
255 4 my ($a,$b) = ($1,$2);
256 4 foreach my $char (sort keys %EthiopicClasses) {
257 300 ▶ next if ( length($char) > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if length $char > 1 116 184 300
258 184 ▶ next unless ( (ord($a) <= ord($char)) && (ord($char) <= ord($b)) );
Branch: 1 branch
BranchTrueFalseTotal
unless ord $a <= ord $char and ord $char <= ord $b 172 12 184
Condition100%3/3
ord $a <= ord $char and ord $char <= ord $b
!ll&&!rl&&r
4013212
MC/DC100%2/2
ord $a <= ord $char and ord $char <= ord $b
ord $a <= ord $char ord $char <= ord $b
Truth table100%3/3
A and B
A= ord $a <= ord $charB= ord $char <= ord $b
ABresult
0X0
100
111
259 12 ▶ if ( $form eq "all" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form eq 'all') { } 0 12 12
260 0 $re .= $EthiopicClasses{$char};
261 }
262 else {
263 12 $EthiopicClasses{$form} =~ /([$EthiopicClasses{$char}])/;
264 12 $re .= $1;
265 }
266 }
267 }
268 else {
269 4 my $geez = setForm( $_, $ግዕዝ);
270 4 ▶ if ( $form eq "all" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form eq 'all') { } 0 4 4
271 0 $re .= $EthiopicClasses{$geez};
272 }
273 else {
274 4 $EthiopicClasses{$form} =~ /([$EthiopicClasses{$geez}])/;
275 4 $re .= $1;
276 }
277 }
278 }
279  
280 4 $re;
281 }
282  
283  
284 sub setRange
285 1 ▶{
Subroutine setRange: called CC=8 SCAR=21.8
Pod undocumented
286 1 my ($chars,$forms,$not) = @_;
287 1 ▶$not ||= $_[3];
Condition33%1/3
$not ||= $_[3]
l!l&&r!l&&!r
001
MC/DC0%0/2
$not ||= $_[3]
$not $_[3]
Truth table33%1/3
A ||= B
A= $notB= $_[3]
ABresult
1X1
011
000
288  
289 1 my $re;
290  
291 1 ▶ if ( $forms eq "all" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($forms eq 'all') { } 0 1 1
292 0 $re = handleChars ( $chars, $forms );
293 }
294 else {
295 1 my @Forms = split ( /,/, $forms);
296 1 foreach (@Forms) {
297 2 ▶ if ( /(\d)-(\d)/o ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(\d)-(\d)/o) { } 1 1 2
298 1 my ($a,$b) = ($1,$2);
299 1 foreach my $form ($a..$b) {
300 3 $re .= handleChars ( $chars, $form );
301 }
302 }
303 else {
304 1 my $form = $_;
305 1 $re .= handleChars ( $chars, $form );
306 }
307 }
308 }
309  
310 1 ▶ ($re) ? ($not) ? "[$not$re]" : "[$re]" : "";
Branch: 2 branches
BranchTrueFalseTotal
$re ? : 1 0 1
$not ? : 0 1 1
311 }
312  
313  
314 sub getRe
315 7 ▶{
Subroutine getRe: called CC=4 SCAR=14.9
Pod undocumented
316 7 ▶$_ = ($#_) ? $_[1] : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
$#_ ? : 0 7 7
317  
318  
319 7 ▶ s/\[:(\p{Ethiopic}+|\w+):\]/($EthiopicClasses{$1}) ? "[$EthiopicClasses{$1}]" : "[:$1:]"/eog;
Branch: 1 branch
BranchTrueFalseTotal
$EthiopicClasses{$1} ? : 2 0 2
320 7 ▶ s/\[#(\p{Ethiopic}|\d)#\]/($EthiopicClasses{$1}) ? "[$EthiopicClasses{$1}]" : ""/eog;
Branch: 1 branch
BranchTrueFalseTotal
$EthiopicClasses{$1} ? : 1 0 1
321 0 s/\[#(\^)?([\d,-]+)#\]/setRange("all",$2,$1)/eog;
322 0 s/\[#(\^)?([\p{Ethiopic},-]+)#\]/setRange($2,"all",$1)/eog;
323  
324 # print " IN: $_\n";
325  
326 #
327 # for some stupid reason the below doesn't work, so \w
328 # is used in place of \p{Ethiopic}, dangerous...
329 #
330 # test 9 in examples/overload.pl will fail
331 #
332 # s/(\p{Ethiopic})\{#([\d,-]+)#\}/setRange($1,$2)/eog;
333 0 s/(\w)\{#([\d,-]+)#\}/setRange($1,$2)/eog;
334  
335 7 s/\[(\^)?(\p{Ethiopic}+.*?)\]\{(\^)?#([\d,-]+)#\}/setRange($2,$4,$1,$3)/eog;
336  
337 # print " OUT: $_\n";
338  
339 7 $_;
340 }
341  
342  
343  
344 #########################################################
345 # Do not change this, Do not put anything below this.
346 # File must return "true" value at termination
347 1 1;
348 ##########################################################
349  
350  
351 __END__
↑ Summary Ethiopic/Amharic.pm »