File Coverage

blib/lib/Encode/Arabic/Habash.pm
Criterion Covered Total %
statement 75 75 100.0
branch 32 62 51.6
condition 2 6 33.3
subroutine 16 16 100.0
pod 2 6 33.3
total 127 165 76.9


line stmt bran cond sub pod time code
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             our $VERSION = '14.1';
8              
9 2     2   13380 use 5.008;
  2         5  
10              
11 2     2   6 use strict;
  2         1  
  2         27  
12 2     2   5 use warnings;
  2         1  
  2         36  
13              
14 2     2   5 use Scalar::Util 'blessed';
  2         2  
  2         103  
15              
16 2     2   395 use Encode::Encoding;
  2         7014  
  2         47  
17 2     2   7 use base 'Encode::Encoding';
  2         2  
  2         726  
18              
19             __PACKAGE__->Define('Habash', 'Soudi', 'HSB');
20              
21              
22             our $enmode;
23             our $demode;
24              
25             our $optxml;
26              
27             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 2 50 33 2   11 $optxml = defined $_[1] && $_[1] eq ':xml' ? 1 : 0;
58              
59 2         3 __PACKAGE__->enmode('full');
60 2         20 __PACKAGE__->demode('full');
61              
62 2         3 splice @_, 1, 1;
63              
64 2         9 require Encode;
65              
66 2 100       20 push @Encode::ISA, 'Exporter' unless Encode->can('export_to_level');
67              
68 2         229 Encode->export_to_level(1, @_);
69             }
70              
71              
72             sub encode ($$;$) {
73 2     2 1 994 my (undef, $text, $check) = @_;
74              
75 2 50       5 $_[1] = '' if $check; # needed by in-place edit
76              
77 2         43 $text = encoder $text;
78              
79 2 50       9 $text = Encode::encode "utf8", $text if Encode::is_utf8($text);
80              
81 2         29 return $text;
82             }
83              
84              
85             sub decode ($$;$) {
86 2     2 1 375 my (undef, $text, $check) = @_;
87              
88 2 50       5 $_[1] = '' if $check; # needed by in-place edit
89              
90 2 50       8 $text = Encode::decode "utf8", $text unless Encode::is_utf8($text);
91              
92 2         78 $text = decoder $text;
93              
94 2         3 return $text;
95             }
96              
97              
98             sub enmode ($$;$$) {
99 2     2 0 3 my ($cls, $mode, $xml, $kshd) = @_;
100              
101 2 50       4 $cls = blessed $cls if ref $cls;
102 2 50       5 $xml = $optxml unless defined $xml;
103              
104 2 50       4 $mode = 'undef' unless defined $mode;
105 2 50       4 $mode = $modemap{$mode} if exists $modemap{$mode};
106              
107 2     2   8 no strict 'refs';
  2         2  
  2         367  
108              
109 2         2 my $return = ${ $cls . '::enmode' };
  2         6  
110              
111 2 50       3 if (defined $mode) {
112              
113 2         1 ${ $cls . '::enmode' } = $mode;
  2         4  
114              
115 2 50       618 my @set = (
    50          
    50          
    50          
    50          
    50          
    50          
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 2         2 undef &encoder;
162              
163 1     1 0 424 eval q /
  1     2   26  
  1         11  
  2         164  
  2         35  
  2         4  
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 2         4540 return $return;
176             }
177              
178              
179             sub demode ($$;$$) {
180 2     2 0 3 my ($cls, $mode, $xml, $kshd) = @_;
181              
182 2 50       6 $cls = blessed $cls if ref $cls;
183 2 50       4 $xml = $optxml unless defined $xml;
184              
185 2 50       4 $mode = 'undef' unless defined $mode;
186 2 50       6 $mode = $modemap{$mode} if exists $modemap{$mode};
187              
188 2     2   7 no strict 'refs';
  2         2  
  2         301  
189              
190 2         2 my $return = ${ $cls . '::demode' };
  2         6  
191              
192 2 50       5 if (defined $mode) {
193              
194 2         0 ${ $cls . '::demode' } = $mode;
  2         4  
195              
196 2 50       23 my @set = (
    50          
    50          
    50          
    50          
    50          
    50          
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{0627}\x{0628}\x{0629}\x{062A}\x{062B}\x{062C}\x{062D}\x{062E}] .
224             q [\x{062F}\x{0630}\x{0631}\x{0632}\x{0633}\x{0634}\x{0635}\x{0636}\x{0637}\x{0638}\x{0639}] .
225             q [\x{063A}\x{0641}\x{0642}\x{0643}\x{0644}\x{0645}\x{0646}\x{0647}\x{0648}\x{0649}\x{064A}] .
226             q [\x{067E}\x{0686}\x{0698}\x{06A4}\x{06AF}] .
227             q [\x{0660}\x{0661}\x{0662}\x{0663}\x{0664}\x{0665}\x{0666}\x{0667}\x{0668}\x{0669}] .
228             ( $mode == 0
229             ? q [\x{0671}]
230             : q [\x{0627}] ) .
231             ( $mode == 1
232             ? ''
233             : q [\x{0651}] . ( $mode == 2
234             ? ''
235             : q [\x{064B}\x{064C}\x{064D}\x{064E}\x{064F}\x{0650}\x{0670}] . ( $mode == 3
236             ? ''
237             : q [\x{0652}] ) ) )
238              
239             );
240              
241              
242 2         2 undef &decoder;
243              
244 2 50 33 2 0 167 eval q /
  2         23  
  2         4  
245              
246             sub decoder ($) {
247              
248             $_[0] =~ tr[/ . $set[0] . q /]
249             [/ . $set[1] . q /]/ . (($kshd or $mode > 0) ? 'd' : '') . q /;
250              
251             return $_[0];
252             }
253             /;
254             }
255              
256 2         1246 return $return;
257             }
258              
259              
260             1;
261              
262             __END__