lib/Convert/Braille.pm

filter: Statementstmt 91.5% 76 / 83 Branchbran 58.0% 29 / 50 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 13 / 13 Podpod 100% 6 / 6 totaltotal 77.7% 126 / 162 CC 31 SCAR 24.4
CC
31
Cov
77%
brailleUnicode_To_DotNumbers
20.2
brailleDotNumbers_To_Unicode
13.7
brailleUnicode_To_Ascii
3.3
CRAP 11.5
↑ Summary blib/lib/Convert/Braille/English.pm »
1 package Convert::Braille;
2 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 BEGIN
5 1 ▶{
Subroutine BEGIN: called CC=2 SCAR=6.9
6 1 require 5.006;
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use vars qw( @EXPORT @EXPORT_OK $VERSION %BrailleAscii_To_Unicode %BrailleUnicode_To_Ascii $dot_separator );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 $VERSION = '0.06';
14  
15 1 @EXPORT = qw(
16 brailleDotNumbers_To_Unicode
17 brailleUnicode_To_DotNumbers
18 brailleUnicode_To_Ascii
19 brailleAscii_To_Unicode
20  
21 brailleAscii_To_DotNumbers
22 brailleDotNumbers_To_Ascii
23 );
24 1 @EXPORT_OK = qw(
25 brailleDotNumbers_To_Unicode
26 brailleUnicode_To_DotNumbers
27 brailleUnicode_To_Ascii
28 brailleAscii_To_Unicode
29  
30 brailleAscii_To_DotNumbers
31 brailleDotNumbers_To_Ascii
32  
33 %BrailleAscii_To_Unicode
34 %Unicode_To_BrailleAscii
35 );
36  
37 1 %BrailleAscii_To_Unicode =(
38 A => '⠁',
39 B => '⠃',
40 C => '⠉',
41 D => '⠙',
42 E => '⠑',
43 F => '⠋',
44 G => '⠛',
45 H => '⠓',
46 I => '⠊',
47 J => '⠚',
48 K => '⠅',
49 L => '⠇',
50 M => '⠍',
51 N => '⠝',
52 O => '⠕',
53 P => '⠏',
54 Q => '⠟',
55 R => '⠗',
56 S => '⠎',
57 T => '⠞',
58 U => '⠥',
59 V => '⠧',
60 W => '⠺',
61 X => '⠭',
62 Y => '⠽',
63 Z => '⠵',
64  
65 1 => '⠂',
66 2 => '⠆',
67 3 => '⠒',
68 4 => '⠲',
69 5 => '⠢',
70 6 => '⠖',
71 7 => '⠶',
72 8 => '⠦',
73 9 => '⠔',
74 0 => '⠴',
75  
76 ',' => '⠄',
77 '@' => '⠈',
78 '/' => '⠌',
79 '"' => '⠐',
80 '^' => '⠘',
81 '>' => '⠜',
82 '\'' => '⠠',
83 '*' => '⠡',
84 '<' => '⠣',
85 '-' => '⠤',
86 '.' => '⠨',
87 '%' => '⠩',
88 '[' => '⠪',
89 '$' => '⠫',
90 '+' => '⠬',
91 '!' => '⠮',
92 '&' => '⠯',
93 ';' => '⠰',
94 ':' => '⠱',
95 '\\' => '⠳',
96 '(' => '⠷',
97 '_' => '⠸',
98 '?' => '⠹',
99 ']' => '⠻',
100 '#' => '⠼',
101 ')' => '⠾',
102 '=' => '⠿'
103 );
104  
105  
106 1 foreach ( keys %BrailleAscii_To_Unicode ) {
107 63 $BrailleUnicode_To_Ascii{$BrailleAscii_To_Unicode{$_}} = $_;
108 }
109  
110 1 $dot_separator = "";
111  
112 }
113  
114 sub _convert
115 25 ▶{
Subroutine _convert: called CC=3 SCAR=11.7
116 25 ▶ return unless ( defined($_[0]) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 25 25
117  
118 25 my ( $token, $hash ) = @_;
119  
120 25 ▶ ( exists($hash->{$token}) ) ? $hash->{$token} : $token ;
Branch: 1 branch
BranchTrueFalseTotal
exists $hash->{$token} ? : 25 0 25
121 }
122  
123  
124 sub brailleAscii_To_Unicode
125 3 ▶{
Subroutine brailleAscii_To_Unicode: called CC=2 SCAR=7.0
Pod documented
126  
127 3 ▶ return unless ( defined($_[0]) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 3 3
128  
129 3 my $ascii = uc($_[0]);
130 3 $ascii =~ s/(.)/_convert ( $1, \%BrailleAscii_To_Unicode )/ge;
131 3 $ascii;
132 }
133  
134  
135 sub brailleUnicode_To_Ascii
136 2 ▶{
Subroutine brailleUnicode_To_Ascii: called CC=3 SCAR=12.0
Pod documented
137  
138 2 ▶ return unless ( defined($_[0]) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 2 2
139  
140 2 my $unicode = $_[0];
141  
142 #
143 # first strip off dots 7 and 8:
144 #
145 2 ▶ if ( $unicode =~ /⡀-⣿/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unicode =~ /\x{2840}-\x{28ff}/) 0 2 2
146 0 $unicode =~ tr/⢀-⣿/⠀-⡿/; # fold upper half
147 0 $unicode =~ tr/⡀-⡿/⠀-⠿/; # fold upper quarter
148 }
149 2 $unicode =~ s/(.)/_convert ( $1, \%BrailleUnicode_To_Ascii )/ge;
150 2 $unicode;
151 }
152  
153  
154 sub brailleUnicode_To_DotNumbers
155 2 ▶{
Subroutine brailleUnicode_To_DotNumbers: called CC=16 SCAR=30.1
Pod documented
156  
157 2 my $string = shift; # no || "" because fail for '0'
158 2 ▶ return "" if !defined $string || $string eq "";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $string or $string eq "" 0 2 2
Condition33%1/3
not defined $string or $string eq ""
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined $string or $string eq ""
not defined $string $string eq ""
Truth table33%1/3
not(A) or B
A= not defined $stringB= $string eq ""
ABresult
1X1
011
000
159 2 ▶ my $braced = ( @_ ) ? shift : 0 ;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 2 2
160  
161 2 my @chars = split ( //, $string );
162  
163 2 my ($trans, $dots);
164  
165 2 foreach ( @chars ) {
166 10 ▶ if ( /[⠀-⣿]/ ) { # assume UTF8
Branch: 1 branch
BranchTrueFalseTotal
if (/[\x{2800}-\x{28ff}]/) { } 10 0 10
167 10 my $char = ord ( $_ ) - 0x2800;
168 10 ▶ $trans .= $dot_separator if ( $dots );
Branch: 1 branch
BranchTrueFalseTotal
if $dots 8 2 10
169 10 $dots = undef;
170 10 ▶ $dots = "1" if ( $char & 0x1 );
Branch: 1 branch
BranchTrueFalseTotal
if $char & 1 10 0 10
171 10 ▶ $dots .= "2" if ( $char & 0x2 );
Branch: 1 branch
BranchTrueFalseTotal
if $char & 2 6 4 10
172 10 ▶ $dots .= "3" if ( $char & 0x4 );
Branch: 1 branch
BranchTrueFalseTotal
if $char & 4 6 4 10
173 10 ▶ $dots .= "4" if ( $char & 0x8 );
Branch: 1 branch
BranchTrueFalseTotal
if $char & 8 0 10 10
174 10 ▶ $dots .= "5" if ( $char & 0x10 );
Branch: 1 branch
BranchTrueFalseTotal
if $char & 16 6 4 10
175 10 ▶ $dots .= "6" if ( $char & 0x20 );
Branch: 1 branch
BranchTrueFalseTotal
if $char & 32 0 10 10
176 10 ▶ $dots .= "7" if ( $char & 0x40 );
Branch: 1 branch
BranchTrueFalseTotal
if $char & 64 0 10 10
177 10 ▶ $dots .= "8" if ( $char & 0x80 );
Branch: 1 branch
BranchTrueFalseTotal
if $char & 128 0 10 10
178 10 ▶ $trans .= ($braced) ? "[$dots]" : $dots;
Branch: 1 branch
BranchTrueFalseTotal
$braced ? : 0 10 10
179 }
180 else {
181 0 $trans .= "$_";
182 0 $dots = undef;
183 }
184 }
185  
186 2 $trans;
187 }
188  
189  
190 sub brailleDotNumbers_To_Unicode
191 2 ▶{
Subroutine brailleDotNumbers_To_Unicode: called CC=10 SCAR=26.2
Pod documented
192  
193 2 my $string = shift;
194 2 ▶ return "" if !defined $string || $string eq "";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $string or $string eq "" 0 2 2
Condition33%1/3
not defined $string or $string eq ""
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined $string or $string eq ""
not defined $string $string eq ""
Truth table33%1/3
not(A) or B
A= not defined $stringB= $string eq ""
ABresult
1X1
011
000
195  
196 2 ▶ $string =~ s/$dot_separator//g if( $dot_separator );
Branch: 1 branch
BranchTrueFalseTotal
if $dot_separator 0 2 2
197  
198  
199 2 my @bits = split ( //, $string );
200  
201 2 my ($char, $lastBit, $trans) = (0,0,"");
202  
203 2 foreach ( @bits ) {
204 28 my $bit = $_;
205 28 ▶ if ( $bit =~ /[1-8]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bit =~ /[1-8]/) { } 28 0 28
206 28 ▶ if ( $bit > $lastBit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bit > $lastBit) { } 20 8 28
207 # bit continues sequence
208 20 $char += 2**($bit-1);
209 }
210 else {
211 # bit starts new sequence
212 8 ▶ $trans .= chr ( 0x2800+$char ) if ( $char ); # first time problem
Branch: 1 branch
BranchTrueFalseTotal
if $char 8 0 8
213 8 $lastBit = $char = 0;
214 8 $char = 2**($bit-1);
215 }
216 28 $lastBit = $bit;
217 }
218 else { # end of sequence
219 0 ▶ $trans .= chr ( 0x2800+$char ) if ( $char ); # first time problem
Branch: 1 branch
BranchTrueFalseTotal
if $char 0 0 0
220 0 $trans .= $bit;
221 0 $lastBit = $char = 0;
222 }
223 }
224 2 ▶ $trans .= chr ( 0x2800+$char ) if ( $char ); # last time problem
Branch: 1 branch
BranchTrueFalseTotal
if $char 2 0 2
225
226 2 $trans;
227 }
228  
229  
230 sub brailleAscii_To_DotNumbers
231 1 ▶{
Subroutine brailleAscii_To_DotNumbers: called CC=1 SCAR=0.0
Pod documented
232 1 brailleUnicode_To_DotNumbers ( brailleAscii_To_Unicode ( @_ ) );
233 }
234  
235  
236 sub brailleDotNumbers_To_Ascii
237 1 ▶{
Subroutine brailleDotNumbers_To_Ascii: called CC=1 SCAR=0.0
Pod documented
238 1 brailleUnicode_To_Ascii ( brailleDotNumbers_To_Unicode ( @_ ) );
239 }
240  
241  
242 #########################################################
243 # Do not change this, Do not put anything below this.
244 # File must return "true" value at termination
245 1 1;
246 ##########################################################
247  
248 __END__
↑ Summary blib/lib/Convert/Braille/English.pm »