blib/lib/Encode/Arabic/Habash.pm

filter: Statementstmt 100% 79 / 79 Branchbran 50.0% 30 / 60 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 15 / 15 Podpod 33.3% 2 / 6 totaltotal 76.9% 127 / 165 SCAR 37.8
CC
32
Cov
77%
enmode
16.7
demode
16.7
import
4.4
CRAP 43.7
« blib/lib/Encode/Arabic/Buckwalter.pm ↑ Summary blib/lib/Encode/Arabic/Parkinson.pm »
1 # ###################################################################### Otakar Smrz, 2003/01/23
2 #
3 # Encoding of Arabic: Habash-Soudi-Buckwalter Notation ############################## 2003/06/19
4  
5 package Encode::Arabic::Habash;
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('Habash', 'Soudi', 'HSB');
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 1 ▶ $optxml = defined $_[1] && $_[1] eq ':xml' ? 1 : 0;
Subroutine import: called CC=4 SCAR=14.8
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] && $_[1] eq ':xml' ? : 0 1 1
Condition33%1/3
defined $_[1] and $_[1] eq ":xml"
!ll&&!rl&&r
100
MC/DC0%0/2
defined $_[1] and $_[1] eq ":xml"
defined $_[1] $_[1] eq ":xml"
Truth table33%1/3
A and B
A= defined $_[1]B= $_[1] eq ":xml"
ABresult
0X0
100
111
58  
59 1 __PACKAGE__->enmode('full');
60 1 __PACKAGE__->demode('full');
61  
62 1 splice @_, 1, 1;
63  
64 1 require Encode;
65  
66 1 ▶ push @Encode::ISA, 'Exporter' unless Encode->can('export_to_level');
Branch: 1 branch
BranchTrueFalseTotal
unless "Encode"->can("export_to_level") 1 0 1
67  
68 1 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 2 ▶ my (undef, $text, $check) = @_;
Subroutine decode: called CC=3 SCAR=11.3
Pod documented
87  
88 2 ▶ $_[1] = '' if $check; # needed by in-place edit
Branch: 1 branch
BranchTrueFalseTotal
if $check 0 2 2
89  
90 2 ▶ $text = Encode::decode "utf8", $text unless Encode::is_utf8($text);
Branch: 1 branch
BranchTrueFalseTotal
unless &Encode::is_utf8($text) 2 0 2
91  
92 2 $text = decoder $text;
93  
94 2 return $text;
95 }
96  
97  
98 sub enmode ($$;$$) {
99 1 ▶ my ($cls, $mode, $xml, $kshd) = @_;
Subroutine enmode: called CC=13 SCAR=28.1
Pod undocumented
100  
101 1 ▶ $cls = blessed $cls if ref $cls;
Branch: 1 branch
BranchTrueFalseTotal
if ref $cls 0 1 1
102 1 ▶ $xml = $optxml unless defined $xml;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $xml 1 0 1
103  
104 1 ▶ $mode = 'undef' unless defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 0 1 1
105 1 ▶ $mode = $modemap{$mode} if exists $modemap{$mode};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Encode::Arabic::Habash::modemap{$mode} 1 0 1
106  
107 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
108  
109 1 my $return = ${ $cls . '::enmode' };
110  
111 1 ▶ if (defined $mode) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mode) 1 0 1
112  
113 1 ${ $cls . '::enmode' } = $mode;
114  
115 1 ▶ my @set = (
Branch: 7 branches
BranchTrueFalseTotal
$kshd ? : 0 1 1
$kshd ? : 0 1 1
$kshd ? : 0 1 1
$mode == 0 ? : 1 0 1
$mode == 1 ? : 0 1 1
$mode == 2 ? : 0 1 1
$mode == 3 ? : 0 1 1
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 [\x{005F}] ) .
138 q [\x{00C2}\x{0175}\x{01CD}] .
139 q [\x{002C}\x{003B}\x{003F}] .
140 q [\x{0027}\x{0100}\x{0177}\x{0041}\x{0062}\x{0127}\x{0074}\x{03B8}\x{006A}\x{0048}\x{0078}] .
141 q [\x{0064}\x{00F0}\x{0072}\x{007A}\x{0073}\x{0161}\x{0053}\x{0044}\x{0054}\x{010E}\x{03C2}] .
142 q [\x{03B3}\x{0066}\x{0071}\x{006B}\x{006C}\x{006D}\x{006E}\x{0068}\x{0077}\x{00FD}\x{0079}] .
143 q [\x{0070}\x{0063}\x{017E}\x{0076}\x{0067}] .
144 q [0-9] .
145 ( $mode == 0
146 ? q [\x{00C4}]
147 : q [\x{0041}] ) .
148 ( $mode == 1
149 ? ''
150 : q [\x{007E}] .
151 ( $mode == 2
152 ? ''
153 : q [\x{00E3}\x{0169}\x{0129}\x{0061}\x{0075}\x{0069}\x{00E1}] .
154 ( $mode == 3
155 ? ''
156 : q [\x{00B7}] ) ) )
157  
158 );
159  
160  
161 1 undef &encoder;
162  
163 1 ▶ eval q /
Subroutine encoder: called CC=1 SCAR=0.0
Pod undocumented
164  
165 sub encoder ($) {
166  
167 $_[0] =~ tr[/ . $set[0] . q /]
168 [/ . $set[1] . q /]d;
169  
170 return $_[0];
171 }
172 /;
173 }
174  
175 1 return $return;
176 }
177  
178  
179 sub demode ($$;$$) {
180 1 ▶ my ($cls, $mode, $xml, $kshd) = @_;
Subroutine demode: called CC=13 SCAR=28.1
Pod undocumented
181  
182 1 ▶ $cls = blessed $cls if ref $cls;
Branch: 1 branch
BranchTrueFalseTotal
if ref $cls 0 1 1
183 1 ▶ $xml = $optxml unless defined $xml;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $xml 1 0 1
184  
185 1 ▶ $mode = 'undef' unless defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 0 1 1
186 1 ▶ $mode = $modemap{$mode} if exists $modemap{$mode};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Encode::Arabic::Habash::modemap{$mode} 1 0 1
187  
188 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
189  
190 1 my $return = ${ $cls . '::demode' };
191  
192 1 ▶ if (defined $mode) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mode) 1 0 1
193  
194 1 ${ $cls . '::demode' } = $mode;
195  
196 1 ▶ my @set = (
Branch: 7 branches
BranchTrueFalseTotal
$kshd ? : 0 1 1
$kshd ? : 0 1 1
$kshd ? : 0 1 1
$mode == 0 ? : 1 0 1
$mode == 1 ? : 0 1 1
$mode == 2 ? : 0 1 1
$mode == 3 ? : 0 1 1
197  
198 ( $kshd
199 ? ''
200 : q [\x{005F}] ) .
201 q [\x{00C2}\x{0175}\x{01CD}] .
202 q [\x{002C}\x{003B}\x{003F}] .
203 q [\x{0027}\x{0100}\x{0177}\x{0041}\x{0062}\x{0127}\x{0074}\x{03B8}\x{006A}\x{0048}\x{0078}] .
204 q [\x{0064}\x{00F0}\x{0072}\x{007A}\x{0073}\x{0161}\x{0053}\x{0044}\x{0054}\x{010E}\x{03C2}] .
205 q [\x{03B3}\x{0066}\x{0071}\x{006B}\x{006C}\x{006D}\x{006E}\x{0068}\x{0077}\x{00FD}\x{0079}] .
206 q [\x{0070}\x{0063}\x{017E}\x{0076}\x{0067}] .
207 q [0-9] .
208 q [\x{00C4}] .
209 q [\x{007E}] .
210 q [\x{00E3}\x{0169}\x{0129}\x{0061}\x{0075}\x{0069}\x{00E1}] .
211 q [\x{00B7}] .
212 ( $kshd
213 ? q [\x{005F}]
214 : '' )
215  
216 ,
217  
218 ( $kshd
219 ? ''
220 : q [\x{0640}] ) .
221 q [\x{0623}\x{0624}\x{0625}] .
222 q [\x{060C}\x{061B}\x{061F}] .
223 q [\x{0621}\x{0622}\x{0626}-\x{063A}\x{0641}-\x{064A}] .
224 q [\x{067E}\x{0686}\x{0698}\x{06A4}\x{06AF}] .
225 q [\x{0660}-\x{0669}] .
226 ( $mode == 0
227 ? q [\x{0671}]
228 : q [\x{0627}] ) .
229 ( $mode == 1
230 ? ''
231 : q [\x{0651}] . ( $mode == 2
232 ? ''
233 : q [\x{064B}-\x{0650}\x{0670}] . ( $mode == 3
234 ? ''
235 : q [\x{0652}] ) ) )
236  
237 );
238  
239  
240 1 undef &decoder;
241  
242 1 ▶ eval q /
Subroutine decoder: called CC=1 SCAR=0.0
Pod undocumented
243  
244 sub decoder ($) {
245  
246 $_[0] =~ tr[/ . $set[0] . q /]
247 [/ . $set[1] . q /]d;
248  
249 return $_[0];
250 }
251 /;
252 }
253  
254 1 return $return;
255 }
256  
257  
258 1 1;
259  
260 __END__
« blib/lib/Encode/Arabic/Buckwalter.pm ↑ Summary blib/lib/Encode/Arabic/Parkinson.pm »