blib/lib/Encode/Arabic/Buckwalter.pm

filter: Statementstmt 97.4% 77 / 79 Branchbran 56.2% 36 / 64 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 93.3% 14 / 15 Podpod 66.6% 4 / 6 totaltotal 79.2% 134 / 169 SCAR 38.1
CC
34
Cov
79%
enmode
19.9
demode
17.7
import
4.0
CRAP 45.1
« blib/lib/Encode/Arabic/ArabTeX/RE.pm ↑ Summary blib/lib/Encode/Arabic/Habash.pm »
1 # ###################################################################### Otakar Smrz, 2003/01/23
2 #
3 # Encoding of Arabic: Tim Buckwalter's Notation ##################################### 2003/06/19
4  
5 package Encode::Arabic::Buckwalter;
6  
7 1 our $VERSION = '14.1';
8  
9 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use Encode::Encoding;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use base 'Encode::Encoding';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 __PACKAGE__->Define('Buckwalter', 'Tim');
20  
21  
22 1 our $enmode;
23 1 our $demode;
24  
25 1 our $optxml;
26  
27 1 our %modemap = (
28  
29 'default' => 0,
30 'undef' => 0,
31  
32 'fullvocalize' => 0,
33 'full' => 0,
34  
35 'nowasla' => 4,
36  
37 'vocalize' => 3,
38 'nosukuun' => 3,
39  
40 'novocalize' => 2,
41 'novowels' => 2,
42 'none' => 2,
43  
44 'noshadda' => 1,
45 'noneplus' => 1,
46 );
47  
48  
49 # use subs 'encoder', 'decoder'; # ignores later prototypes
50  
51 sub encoder ($); # respect prototypes
52 sub decoder ($); # respect prototypes
53  
54  
55 sub import { # perform import as if Encode were used one level before this module
56  
57 3 ▶ $optxml = defined $_[1] && $_[1] eq ':xml' ? 1 : 0;
Subroutine import: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] && $_[1] eq ':xml' ? : 2 1 3
Condition66%2/3
defined $_[1] and $_[1] eq ":xml"
!ll&&!rl&&r
102
MC/DC50%1/2
defined $_[1] and $_[1] eq ":xml"
defined $_[1] $_[1] eq ":xml"
Truth table66%2/3
A and B
A= defined $_[1]B= $_[1] eq ":xml"
ABresult
0X0
100
111
58  
59 3 __PACKAGE__->enmode('full');
60 3 __PACKAGE__->demode('full');
61  
62 3 splice @_, 1, 1;
63  
64 3 require Encode;
65  
66 3 ▶ push @Encode::ISA, 'Exporter' unless Encode->can('export_to_level');
Branch: 1 branch
BranchTrueFalseTotal
unless "Encode"->can("export_to_level") 1 2 3
67  
68 3 Encode->export_to_level(1, @_);
69 }
70  
71  
72 sub encode ($$;$) {
73 2 ▶ my (undef, $text, $check) = @_;
Subroutine encode: called CC=3 SCAR=11.3
Pod documented
74  
75 2 ▶ $_[1] = '' if $check; # needed by in-place edit
Branch: 1 branch
BranchTrueFalseTotal
if $check 0 2 2
76  
77 2 $text = encoder $text;
78  
79 2 ▶ $text = Encode::encode "utf8", $text if Encode::is_utf8($text);
Branch: 1 branch
BranchTrueFalseTotal
if &Encode::is_utf8($text) 2 0 2
80  
81 2 return $text;
82 }
83  
84  
85 sub decode ($$;$) {
86 4 ▶ my (undef, $text, $check) = @_;
Subroutine decode: called CC=3 SCAR=11.3
Pod documented
87  
88 4 ▶ $_[1] = '' if $check; # needed by in-place edit
Branch: 1 branch
BranchTrueFalseTotal
if $check 0 4 4
89  
90 4 ▶ $text = Encode::decode "utf8", $text unless Encode::is_utf8($text);
Branch: 1 branch
BranchTrueFalseTotal
unless &Encode::is_utf8($text) 4 0 4
91  
92 4 $text = decoder $text;
93  
94 4 return $text;
95 }
96  
97  
98 sub enmode ($$;$$) {
99 3 ▶ my ($cls, $mode, $xml, $kshd) = @_;
Subroutine enmode: called CC=14 SCAR=29.9
Pod documented
100  
101 3 ▶ $cls = blessed $cls if ref $cls;
Branch: 1 branch
BranchTrueFalseTotal
if ref $cls 0 3 3
102 3 ▶ $xml = $optxml unless defined $xml;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $xml 3 0 3
103  
104 3 ▶ $mode = 'undef' unless defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 0 3 3
105 3 ▶ $mode = $modemap{$mode} if exists $modemap{$mode};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Encode::Arabic::Buckwalter::modemap{$mode} 3 0 3
106  
107 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
108  
109 3 my $return = ${ $cls . '::enmode' };
110  
111 3 ▶ if (defined $mode) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mode) 3 0 3
112  
113 3 ${ $cls . '::enmode' } = $mode;
114  
115 3 ▶ my @set = (
Branch: 8 branches
BranchTrueFalseTotal
$kshd ? : 0 3 3
$kshd ? : 0 3 3
$kshd ? : 0 3 3
$xml ? : 2 1 3
$mode == 0 ? : 3 0 3
$mode == 1 ? : 0 3 3
$mode == 2 ? : 0 3 3
$mode == 3 ? : 0 3 3
116  
117 ( $kshd
118 ? ''
119 : q [\x{0640}] ) .
120 q [\x{0623}\x{0624}\x{0625}] .
121 q [\x{060C}\x{061B}\x{061F}] .
122 q [\x{0621}\x{0622}\x{0626}-\x{063A}\x{0641}-\x{064A}] .
123 q [\x{067E}\x{0686}\x{0698}\x{06A4}\x{06AF}] .
124 q [\x{0660}-\x{0669}] .
125 q [\x{0671}] .
126 q [\x{0651}] .
127 q [\x{064B}-\x{0650}\x{0670}] .
128 q [\x{0652}] .
129 ( $kshd
130 ? q [\x{0640}]
131 : '' )
132  
133 ,
134  
135 ( $kshd
136 ? ''
137 : q [_] ) .
138 ( $xml
139 ? q [OWI]
140 : q [>&<] ) .
141 q [,;?] .
142 q ['|}AbptvjHxd*rzs$SDTZEgfqklmnhwYy] .
143 q [PJRVG] .
144 q [0-9] .
145 ( $mode == 0
146 ? q [{]
147 : q [A] ) .
148 ( $mode == 1
149 ? ''
150 : q [~] . ( $mode == 2
151 ? ''
152 : q [FNKaui`] . ( $mode == 3
153 ? ''
154 : q [o] ) ) )
155  
156 );
157  
158  
159 3 undef &encoder;
160  
161 3 ▶ eval q /
Subroutine encoder: not called CC=1 SCAR=2.6
Pod undocumented
162  
163 sub encoder ($) {
164  
165 $_[0] =~ tr[/ . $set[0] . q /]
166 [/ . $set[1] . q /]d;
167  
168 return $_[0];
169 }
170 /;
171 }
172  
173 3 return $return;
174 }
175  
176  
177 sub demode ($$;$$) {
178 3 ▶ my ($cls, $mode, $xml, $kshd) = @_;
Subroutine demode: called CC=14 SCAR=28.7
Pod documented
179  
180 3 ▶ $cls = blessed $cls if ref $cls;
Branch: 1 branch
BranchTrueFalseTotal
if ref $cls 0 3 3
181 3 ▶ $xml = $optxml unless defined $xml;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $xml 3 0 3
182  
183 3 ▶ $mode = 'undef' unless defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 0 3 3
184 3 ▶ $mode = $modemap{$mode} if exists $modemap{$mode};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Encode::Arabic::Buckwalter::modemap{$mode} 3 0 3
185  
186 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
187  
188 3 my $return = ${ $cls . '::demode' };
189  
190 3 ▶ if (defined $mode) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mode) 3 0 3
191  
192 3 ${ $cls . '::demode' } = $mode;
193  
194 3 ▶ my @set = (
Branch: 8 branches
BranchTrueFalseTotal
$kshd ? : 0 3 3
$xml ? : 2 1 3
$kshd ? : 0 3 3
$kshd ? : 0 3 3
$mode == 0 ? : 3 0 3
$mode == 1 ? : 0 3 3
$mode == 2 ? : 0 3 3
$mode == 3 ? : 0 3 3
195  
196 ( $kshd
197 ? ''
198 : q [_] ) .
199 ( $xml
200 ? q [OWI]
201 : q [>&<] ) .
202 q [,;?] .
203 q ['|}AbptvjHxd*rzs$SDTZEgfqklmnhwYy] .
204 q [PJRVG] .
205 q [0-9] .
206 q [{] .
207 q [~] .
208 q [FNKaui`] .
209 q [o] .
210 ( $kshd
211 ? q [_]
212 : '' )
213  
214 ,
215  
216 ( $kshd
217 ? ''
218 : q [\x{0640}] ) .
219 q [\x{0623}\x{0624}\x{0625}] .
220 q [\x{060C}\x{061B}\x{061F}] .
221 q [\x{0621}\x{0622}\x{0626}-\x{063A}\x{0641}-\x{064A}] .
222 q [\x{067E}\x{0686}\x{0698}\x{06A4}\x{06AF}] .
223 q [\x{0660}-\x{0669}] .
224 ( $mode == 0
225 ? q [\x{0671}]
226 : q [\x{0627}] ) .
227 ( $mode == 1
228 ? ''
229 : q [\x{0651}] . ( $mode == 2
230 ? ''
231 : q [\x{064B}-\x{0650}\x{0670}] . ( $mode == 3
232 ? ''
233 : q [\x{0652}] ) ) )
234  
235 );
236  
237  
238 3 undef &decoder;
239  
240 3 ▶ eval q /
Subroutine decoder: called CC=1 SCAR=0.0
Pod undocumented
241  
242 sub decoder ($) {
243  
244 $_[0] =~ tr[/ . $set[0] . q /]
245 [/ . $set[1] . q /]d;
246  
247 return $_[0];
248 }
249 /;
250 }
251  
252 3 return $return;
253 }
254  
255  
256 1 1;
257  
258 __END__
« blib/lib/Encode/Arabic/ArabTeX/RE.pm ↑ Summary blib/lib/Encode/Arabic/Habash.pm »