File Coverage

blib/lib/Encode/Arabic/Parkinson.pm
Criterion Covered Total %
statement 61 71 85.9
branch 30 58 51.7
condition 2 3 66.6
subroutine 12 16 75.0
pod 4 6 66.6
total 109 154 70.7


line stmt bran cond sub pod time code
1             # ###################################################################### Otakar Smrz, 2003/01/23
2             #
3             # Encoding of Arabic: Dil Parkinson's Notation ###################################### 2006/02/03
4              
5             # $Id: Parkinson.pm 179 2007-01-14 00:23:25Z smrz $
6              
7             package Encode::Arabic::Parkinson;
8              
9 2     2   37712 use 5.008;
  2         9  
  2         74  
10              
11 2     2   11 use strict;
  2         5  
  2         72  
12 2     2   9 use warnings;
  2         4  
  2         62  
13              
14 2     2   10 use Scalar::Util 'blessed';
  2         4  
  2         301  
15              
16             our $VERSION = do { q $Revision: 179 $ =~ /(\d+)/; sprintf "%4.2f", $1 / 100 };
17              
18              
19 2     2   742 use Encode::Encoding;
  2         10251  
  2         59  
20 2     2   13 use base 'Encode::Encoding';
  2         3  
  2         992  
21              
22             __PACKAGE__->Define('Parkinson');
23              
24              
25             our $enmode;
26             our $demode;
27              
28             our $optxml;
29              
30             our %modemap = (
31              
32             'default' => 0,
33             'undef' => 0,
34              
35             'fullvocalize' => 0,
36             'full' => 0,
37              
38             'nowasla' => 4,
39              
40             'vocalize' => 3,
41             'nosukuun' => 3,
42              
43             'novocalize' => 2,
44             'novowels' => 2,
45             'none' => 2,
46              
47             'noshadda' => 1,
48             'noneplus' => 1,
49             );
50              
51              
52             # use subs 'encoder', 'decoder'; # ignores later prototypes
53              
54             sub encoder ($); # respect prototypes
55             sub decoder ($); # respect prototypes
56              
57              
58             sub import { # perform import as if Encode were used one level before this module
59              
60 2 100 66 2   29 $optxml = defined $_[1] && $_[1] eq ':xml' ? 1 : 0;
61              
62 2         7 __PACKAGE__->enmode('full');
63 2         12 __PACKAGE__->demode('full');
64              
65 2         5 splice @_, 1, 1;
66              
67 2         18 require Encode;
68              
69 2         71 Encode->export_to_level(1, @_);
70             }
71              
72              
73             sub encode ($$;$) {
74 0     0 1 0 my (undef, $text, $check) = @_;
75              
76 0 0       0 $_[1] = '' if $check; # needed by in-place edit
77              
78 0         0 return encoder $text;
79             }
80              
81              
82             sub decode ($$;$) {
83 0     0 1 0 my (undef, $text, $check) = @_;
84              
85 0 0       0 $_[1] = '' if $check; # needed by in-place edit
86              
87 0         0 return decoder $text;
88             }
89              
90              
91             sub enmode ($$;$$) {
92 2     2 1 5 my ($cls, $mode, $xml, $kshd) = @_;
93              
94 2 50       8 $cls = blessed $cls if ref $cls;
95 2 50       8 $xml = $optxml unless defined $xml;
96              
97 2 50       6 $mode = 'undef' unless defined $mode;
98 2 50       9 $mode = $modemap{$mode} if exists $modemap{$mode};
99              
100 2     2   11 no strict 'refs';
  2         5  
  2         554  
101              
102 2         3 my $return = ${ $cls . '::enmode' };
  2         9  
103              
104 2 50       6 if (defined $mode) {
105              
106 2         3 ${ $cls . '::enmode' } = $mode;
  2         7  
107              
108 2 50       33 my @set = (
    50          
    50          
    100          
    50          
    50          
    50          
    50          
109              
110             ( $kshd
111             ? ''
112             : q [\x{0640}] ) .
113             q [\x{0623}\x{0624}\x{0625}] .
114             q [\x{060C}\x{061B}\x{061F}] .
115             q [\x{0621}\x{0622}\x{0626}-\x{063A}\x{0641}-\x{064A}] .
116             # q [\x{067E}\x{0686}\x{0698}\x{06A4}\x{06AF}] .
117             q [\x{0660}-\x{0669}] .
118             q [\x{0671}] .
119             q [\x{0651}] .
120             q [\x{064B}-\x{0650}\x{0670}] .
121             q [\x{0652}] .
122             ( $kshd
123             ? q [\x{0640}]
124             : '' )
125              
126             ,
127              
128             ( $kshd
129             ? ''
130             : q [_] ) .
131             ( $xml
132             ? q [LWE]
133             : q [LWE] ) .
134             q [,;?] .
135             q [CMYAbQtVjHxdvrzspSDTZcgfqklmnhwey] .
136             # q [PJRVG] .
137             q [0-9] .
138             ( $mode == 0
139             ? q [O]
140             : q [A] ) .
141             ( $mode == 1
142             ? ''
143             : q [~] . ( $mode == 2
144             ? ''
145             : q [NUIauiR] . ( $mode == 3
146             ? ''
147             : q [o] ) ) )
148              
149             );
150              
151              
152 2         6 undef &encoder;
153              
154 2     0 0 205 eval q /
  0     1   0  
  0         0  
  1         730  
  1         27  
  1         11  
155              
156             sub encoder ($) {
157              
158             $_[0] =~ tr[/ . $set[0] . q /]
159             [/ . $set[1] . q /]d;
160              
161             return $_[0];
162             }
163             /;
164             }
165              
166 2         7325 return $return;
167             }
168              
169              
170             sub demode ($$;$$) {
171 2     2 1 5 my ($cls, $mode, $xml, $kshd) = @_;
172              
173 2 50       7 $cls = blessed $cls if ref $cls;
174 2 50       7 $xml = $optxml unless defined $xml;
175              
176 2 50       8 $mode = 'undef' unless defined $mode;
177 2 50       9 $mode = $modemap{$mode} if exists $modemap{$mode};
178              
179 2     2   11 no strict 'refs';
  2         4  
  2         384  
180              
181 2         4 my $return = ${ $cls . '::demode' };
  2         9  
182              
183 2 50       10 if (defined $mode) {
184              
185 2         5 ${ $cls . '::demode' } = $mode;
  2         7  
186              
187 2 50       43 my @set = (
    100          
    50          
    50          
    50          
    50          
    50          
    50          
188              
189             ( $kshd
190             ? ''
191             : q [_] ) .
192             ( $xml
193             ? q [LWE]
194             : q [LWE] ) .
195             q [,;?] .
196             q [CMYAbQtVjHxdvrzspSDTZcgfqklmnhwey] .
197             # q [PJRVG] .
198             q [0-9] .
199             q [O] .
200             q [~] .
201             q [NUIauiR] .
202             q [o] .
203             ( $kshd
204             ? q [_]
205             : '' )
206              
207             ,
208              
209             ( $kshd
210             ? ''
211             : q [\x{0640}] ) .
212             q [\x{0623}\x{0624}\x{0625}] .
213             q [\x{060C}\x{061B}\x{061F}] .
214             q [\x{0621}\x{0622}\x{0626}-\x{063A}\x{0641}-\x{064A}] .
215             # q [\x{067E}\x{0686}\x{0698}\x{06A4}\x{06AF}] .
216             q [\x{0660}-\x{0669}] .
217             ( $mode == 0
218             ? q [\x{0671}]
219             : q [\x{0627}] ) .
220             ( $mode == 1
221             ? ''
222             : q [\x{0651}] . ( $mode == 2
223             ? ''
224             : q [\x{064B}-\x{0650}\x{0670}] . ( $mode == 3
225             ? ''
226             : q [\x{0652}] ) ) )
227              
228             );
229              
230              
231 2         6 undef &decoder;
232              
233 2     0 0 154 eval q /
  0         0  
  0         0  
234              
235             sub decoder ($) {
236              
237             $_[0] =~ tr[/ . $set[0] . q /]
238             [/ . $set[1] . q /]d;
239              
240             return $_[0];
241             }
242             /;
243             }
244              
245 2         2077 return $return;
246             }
247              
248              
249             1;
250              
251             __END__