Phonetic.pm

filter: Statementstmt 39.5% 34 / 86 Branchbran 33.3% 16 / 48 Conditioncond 26.6% 8 / 30 MC/DCmcdc 10.5% 2 / 19 Subroutinesub 40.0% 2 / 5 Podpod 0.0% 0 / 4 totaltotal 32.2% 62 / 192 CC 38 SCAR 44.5
CC
38
Cov
35%
translate
107.8
romanise
72.0
rmap
20.0
CRAP 85.2
↑ Summary Translate.pm »
1 # Used to translate roman key board strokes to Unicode.
2
3 package Unicode::Indic::Phonetic;
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = 0.01;
6
7 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
8 0 my $proto = shift;
9 0 ▶ my $class = ref($proto)||$proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
10 0 my $self = {
11 @_
12 };
13 }
14
15 1 ▶sub translate{
Subroutine translate: called CC=27 SCAR=46.8
Pod undocumented
16 1 my $self = shift;
17 1 my $map = $self ->{Map};
18 1 my $text = shift;
19 1 my $prev = '';
20 1 my $boc = 1;
21 1 my $out;
22 1 my $flag = '';
23 1 my $halant = $map->{virama};
24 1 foreach my $ch (split (//, $text),' '){
25 36 ▶ if ($flag ne ''){
Branch: 1 branch
BranchTrueFalseTotal
if ($flag ne "") 0 36 36
26 0 ▶ $flag = '' if ($flag eq '<' && $ch eq '>');
Branch: 1 branch
BranchTrueFalseTotal
if $flag eq "<" and $ch eq ">" 0 0 0
Condition0%0/3
$flag eq "<" and $ch eq ">"
!ll&&!rl&&r
000
MC/DC0%0/2
$flag eq "<" and $ch eq ">"
$flag eq "<" $ch eq ">"
Truth table0%0/3
A and B
A= $flag eq "<"B= $ch eq ">"
ABresult
0X0
100
111
27 0 ▶ $flag = '' if ($flag eq '&' && $ch eq ';');
Branch: 1 branch
BranchTrueFalseTotal
if $flag eq "&" and $ch eq ";" 0 0 0
Condition0%0/3
$flag eq "&" and $ch eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
$flag eq "&" and $ch eq ";"
$flag eq "&" $ch eq ";"
Truth table0%0/3
A and B
A= $flag eq "&"B= $ch eq ";"
ABresult
0X0
100
111
28 0 ▶ if ($flag eq '#' && $ch eq '#'){
Branch: 1 branch
BranchTrueFalseTotal
if ($flag eq "#" and $ch eq "#") 0 0 0
Condition0%0/3
$flag eq "#" and $ch eq "#"
!ll&&!rl&&r
000
MC/DC0%0/2
$flag eq "#" and $ch eq "#"
$flag eq "#" $ch eq "#"
Truth table0%0/3
A and B
A= $flag eq "#"B= $ch eq "#"
ABresult
0X0
100
111
29 0 $flag = '';
30 0 $out .= '\e';
31 0 next;
32 }
33 0 ▶ if ($flag ne ''){
Branch: 1 branch
BranchTrueFalseTotal
if ($flag ne "") 0 0 0
34 0 ▶ $out .= $ch unless $ch eq '#';
Branch: 1 branch
BranchTrueFalseTotal
unless $ch eq "#" 0 0 0
35 0 ▶ $out .= '\e' if $ch eq '#';
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "#" 0 0 0
36 0 next;
37 }
38 }
39 36 ▶ if (!$prev){
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev) 5 31 36
40 5 $prev = $ch;
41 5 next;
42 }
43 31 ▶ $out .= $halant if (!$boc && $prev !~ /[aeiouAEIOUMHR]/);
Branch: 1 branch
BranchTrueFalseTotal
unless $boc or $prev =~ /[aeiouAEIOUMHR]/ 1 30 31
Condition100%3/3
$boc or $prev =~ /[aeiouAEIOUMHR]/
l!l&&r!l&&!r
17131
MC/DC100%2/2
$boc or $prev =~ /[aeiouAEIOUMHR]/
$boc $prev =~ /[aeiouAEIOUMHR]/
Truth table100%3/3
A or B
A= $bocB= $prev =~ /[aeiouAEIOUMHR]/
ABresult
1X1
011
000
44 31 ▶ if (exists $map->{$prev.$ch}){
Branch: 2 branches
BranchTrueFalseTotal
if (exists $$map{$prev . $ch}) { } 4 27 31
elsif (exists $map->{$prev}) { } 23 4 27
45 4 ▶ if ($boc && $ch =~ /[aieouAEIOUMHR]/){
Branch: 1 branch
BranchTrueFalseTotal
if ($boc and $ch =~ /[aieouAEIOUMHR]/) { } 0 4 4
Condition33%1/3
$boc and $ch =~ /[aieouAEIOUMHR]/
!ll&&!rl&&r
400
MC/DC0%0/2
$boc and $ch =~ /[aieouAEIOUMHR]/
$boc $ch =~ /[aieouAEIOUMHR]/
Truth table33%1/3
A and B
A= $bocB= $ch =~ /[aieouAEIOUMHR]/
ABresult
0X0
100
111
46 0 $out .= $map->{'_'.$prev.$ch};
47 }else{
48 4 $out .= $map->{$prev.$ch};
49 }
50 4 $prev ='';
51 4 $boc = ($ch =~ /[aieouAEIOUMHR]/);
52 }elsif (exists $map->{$prev}){
53 23 ▶ if ($boc && $prev =~ /[aieouAEIOUR]/){
Branch: 1 branch
BranchTrueFalseTotal
if ($boc and $prev =~ /[aieouAEIOUR]/) { } 0 23 23
Condition66%2/3
$boc and $prev =~ /[aieouAEIOUR]/
!ll&&!rl&&r
10130
MC/DC0%0/2
$boc and $prev =~ /[aieouAEIOUR]/
$boc $prev =~ /[aieouAEIOUR]/
Truth table66%2/3
A and B
A= $bocB= $prev =~ /[aieouAEIOUR]/
ABresult
0X0
100
111
54 0 $out .= $map->{'_'.$prev};
55 }else{
56 23 ▶ $out .= $map->{$prev} if $map->{$prev};
Branch: 1 branch
BranchTrueFalseTotal
if $map->{$prev} 14 9 23
57 }
58 23 $boc = ($prev =~ /[aieouAEIOUMHR]/);
59 23 $prev = $ch;
60 }else{
61 4 ▶ $out .= $prev unless $prev eq '#';
Branch: 1 branch
BranchTrueFalseTotal
unless $prev eq "#" 4 0 4
62 4 ▶ $out .= '\e' if $prev eq '#';
Branch: 1 branch
BranchTrueFalseTotal
if $prev eq "#" 0 4 4
63 4 $boc = 1;
64 4 ▶ if ((($prev eq '&') || ($prev eq '<'))|| ($prev eq '#')){
Branch: 1 branch
BranchTrueFalseTotal
if ($prev eq '&' or $prev eq '<' or $prev eq '#') { } 0 4 4
Condition33%2/6
$prev eq "&" or $prev eq "<" or $prev eq "#"
l!l&&r!l&&!r
004
$prev eq "&" or $prev eq "<"
l!l&&r!l&&!r
004
MC/DC0%0/3
$prev eq "&" or $prev eq "<" or $prev eq "#"
$prev eq "&" $prev eq "<" $prev eq "#"
Truth table25%1/4
A or B or C
A= $prev eq "&"B= $prev eq "<"C= $prev eq "#"
ABCresult
1XX1
01X1
0011
0000
65 0 $flag = $prev;
66 0 $out .= $ch;
67 0 $prev = '';
68 }else{
69 4 $prev = $ch;
70 }
71 }
72 }
73 1 return $out;
74 }
75
76 0 ▶sub romanise{
Subroutine romanise: not called CC=8 SCAR=42.8
Pod undocumented
77 0 my $self = shift;
78 0 my $map = $self ->{Map};
79 0 ▶ $self->{RMap} = $self->rmap() unless exists $self->{RMap};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"RMap"} 0 0 0
80 0 my $rmap = $self ->{RMap};
81 0 my $base = ord($map->{base});
82 0 my $text = shift;
83 0 my $prev = 'a';
84 0 my $out;
85 0 my $halant = $map->{virama};
86 0 foreach my $ch (split (//, $text),' '){
87 0 ▶ if (ord($ch) >= $base){
Branch: 1 branch
BranchTrueFalseTotal
if (ord $ch >= $base) { } 0 0 0
88 0 my $ch1 .= $rmap->[ord($ch) - $base];
89 0 ▶ if ($ch eq $halant){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq $halant) 0 0 0
90 0 $prev = 'a';
91 0 next;
92 }
93 0 ▶ $out .= 'a' if "$prev.$ch1" !~ /[aeiouAEIOUMHR]/;
Branch: 1 branch
BranchTrueFalseTotal
unless ("$prev.$ch1") =~ /[aeiouAEIOUMHR]/ 0 0 0
94 0 $out .= $ch1;
95 0 $prev = $ch1;
96 }else{
97 0 ▶ $out .= 'a' if $prev !~ /[aeiouAEIOUMHR]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $prev =~ /[aeiouAEIOUMHR]/ 0 0 0
98 0 ▶ $out .= '#' if $ch eq '\e';
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "\\e" 0 0 0
99 0 $out .= $ch;
100 0 $prev = 'a';
101 }
102 }
103 0 return $out;
104 }
105
106 0 ▶sub rmap{
Subroutine rmap: not called CC=4 SCAR=30.0
Pod undocumented
107 0 my $self = shift;
108 0 my $Map = $self->{Map};
109 0 my $base = ord($Map->{base});
110 0 my $RMap = [];
111 0 foreach my $key (sort keys %{$Map}){
112 0 my $v = ord($Map->{$key}) - $base;
113 0 ▶ next if $v < 0 or length $key > 3;
Branch: 1 branch
BranchTrueFalseTotal
if $v < 0 or length $key > 3 0 0 0
Condition0%0/3
$v < 0 or length $key > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$v < 0 or length $key > 3
$v < 0 length $key > 3
Truth table0%0/3
A or B
A= $v < 0B= length $key > 3
ABresult
1X1
011
000
114 #print $v, ": ", $key,"\n";
115 0 $key =~ s/^_//;
116 0 $RMap->[$v] = $key;
117 }
118 0 return $RMap;
119 }
120 1 1;
121
122 __END__
↑ Summary Translate.pm »