blib/lib/Lingua/UK/Translit.pm

filter: Statementstmt 100% 37 / 37 Branchbran 100% 10 / 10 Conditioncond 100% 15 / 15 MC/DCmcdc 100% 8 / 8 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 100% 76 / 76 CC 12 SCAR 22.2
CC
12
Cov
100%
uk2ascii
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 9.2
↑ Summary
1 package Lingua::UK::Translit;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 require Exporter;
9  
10 1 our @ISA = qw(Exporter);
11  
12 1 our %EXPORT_TAGS = ( 'all' => [ qw(
13
14 ) ] );
15  
16 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
17  
18 1 our @EXPORT = qw(
19 &uk2ascii
20
21 );
22  
23 1 our $VERSION = '0.10';
24  
25 1 my %ua2en = (
26 'а' => 'a', 'А' => 'A',
27 'б' => 'b', 'Б' => 'B',
28 'в' => 'v', 'В' => 'V',
29 'г' => 'h', 'Г' => 'H',
30 'ґ' => 'g', 'Ґ' => 'G',
31 'д' => 'd', 'Д' => 'D',
32 'е' => 'e', 'Е' => 'E',
33 'є' => 'ie', 'Є' => 'Ie',
34 'ж' => 'zh', 'Ж' => 'Zh',
35 'з' => 'z', 'З' => 'Z',
36 'и' => 'y', 'И' => 'Y',
37 'і' => 'i', 'І' => 'I',
38 'ї' => 'i', 'Ї' => 'I',
39 'й' => 'i', 'Й' => 'I',
40 'к' => 'k', 'К' => 'K',
41 'л' => 'l', 'Л' => 'L',
42 'м' => 'm', 'М' => 'M',
43 'н' => 'n', 'Н' => 'N',
44 'о' => 'o', 'О' => 'O',
45 'п' => 'p', 'П' => 'P',
46 'р' => 'r', 'Р' => 'R',
47 'с' => 's', 'С' => 'S',
48 'т' => 't', 'Т' => 'T',
49 'у' => 'u', 'У' => 'U',
50 'ф' => 'f', 'Ф' => 'F',
51 'х' => 'kh', 'Х' => 'Kh',
52 'ц' => 'ts', 'Ц' => 'Ts',
53 'ч' => 'ch', 'Ч' => 'Ch',
54 'ш' => 'sh', 'Ш' => 'Sh',
55 'щ' => 'sch', 'Щ' => 'Sch',
56 'ь' => '\'', 'Ь' => '\'',
57 'ю' => 'iu', 'Ю' => 'Iu',
58 'я' => 'ia', 'Я' => 'Ia'
59 );
60  
61 1 my %ua2enwb = (
62 'є' => 'ye', 'Є' => 'Ye',
63 'ї' => 'y', 'Ї' => 'Y',
64 'й' => 'y', 'Й' => 'Y',
65 'ю' => 'yu', 'Ю' => 'Yu',
66 'я' => 'ya', 'Я' => 'Ya'
67 );
68  
69  
70 sub uk2ascii
71 5 ▶{
Subroutine uk2ascii: called CC=12 SCAR=24.8
Pod documented
72 5 my $strin = shift;
73  
74 5 my @words = split ('\b',$strin);
75  
76 5 my $strans = '';
77  
78 5 foreach my $word (@words){
79  
80 49 my @c = split('',$word);
81
82 49 my $wtrans = '';
83
84 49 ▶ for ( my $i = 0; $i <= $#c; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#c) 435 49 484
85 435 ▶ if ( ($i == 0) and (exists $ua2enwb{$c[0]}) ){
Branch: 2 branches
BranchTrueFalseTotal
if ($i == 0 and exists $ua2enwb{$c[0]}) { } 11 424 435
elsif (exists $ua2en{$c[$i]}) { } 269 155 424
Condition100%3/3
$i == 0 and exists $ua2enwb{$c[0]}
!ll&&!rl&&r
3863811
MC/DC100%2/2
$i == 0 and exists $ua2enwb{$c[0]}
$i == 0 exists $ua2enwb{$c[0]}
Truth table100%3/3
A and B
A= $i == 0B= exists $ua2enwb{$c[0]}
ABresult
0X0
100
111
86 11 $wtrans .= $ua2enwb{$c[0]};
87 } elsif (exists $ua2en{$c[$i]}){
88 269 ▶ if ( ($c[$i] eq 'г') and (($c[$i-1] eq 'з') or ($c[$i-1] eq 'З')) ){
Branch: 2 branches
BranchTrueFalseTotal
if ($c[$i] eq "\x{433}" and $c[$i - 1] eq "\x{437}" || $c[$i - 1] eq "\x{417}") { } 2 267 269
elsif ($c[$i] eq "\x{413}" and $c[$i - 1] eq "\x{437}" || $c[$i - 1] eq "\x{417}") { } 2 265 267
Condition100%6/6
$c[$i] eq "\x{433}" and $c[$i - 1] eq "\x{437}" || $c[$i - 1] eq "\x{417}"
!ll&&!rl&&r
26342
$c[$i - 1] eq "\x{437}" or $c[$i - 1] eq "\x{417}"
l!l&&r!l&&!r
114
MC/DC100%3/3
$c[$i] eq "\x{433}" and $c[$i - 1] eq "\x{437}" || $c[$i - 1] eq "\x{417}"
$c[$i] eq "\x{433}" $c[$i - 1] eq "\x{437}" $c[$i - 1] eq "\x{417}"
Truth table100%4/4
A and B or C
A= $c[$i] eq "\x{433}"B= $c[$i - 1] eq "\x{437}"C= $c[$i - 1] eq "\x{417}"
ABCresult
0XX0
1000
11X1
1011
89 2 $wtrans .= 'gh';
90 ▶ } elsif ( ($c[$i] eq 'Г') and (($c[$i-1] eq 'з') or ($c[$i-1] eq 'З')) ){
Condition100%6/6
$c[$i] eq "\x{413}" and $c[$i - 1] eq "\x{437}" || $c[$i - 1] eq "\x{417}"
!ll&&!rl&&r
26142
$c[$i - 1] eq "\x{437}" or $c[$i - 1] eq "\x{417}"
l!l&&r!l&&!r
114
MC/DC100%3/3
$c[$i] eq "\x{413}" and $c[$i - 1] eq "\x{437}" || $c[$i - 1] eq "\x{417}"
$c[$i] eq "\x{413}" $c[$i - 1] eq "\x{437}" $c[$i - 1] eq "\x{417}"
Truth table100%4/4
A and B or C
A= $c[$i] eq "\x{413}"B= $c[$i - 1] eq "\x{437}"C= $c[$i - 1] eq "\x{417}"
ABCresult
0XX0
1000
11X1
1011
91 2 $wtrans .= 'Gh';
92 } else {
93 265 $wtrans .= $ua2en{$c[$i]};
94 }
95 } else {
96 155 $wtrans .= $c[$i];
97 }
98 }
99 49 $strans .= $wtrans;
100 }
101 5 return $strans;
102 }
103  
104 1 1;
105 __END__
↑ Summary