File Coverage

blib/lib/Encode/Arabic/ArabTeX/RE.pm
Criterion Covered Total %
statement 36 177 20.3
branch 2 38 5.2
condition 0 9 0.0
subroutine 12 18 66.6
pod 2 6 33.3
total 52 248 20.9


line stmt bran cond sub pod time code
1             # ################################################################### Otakar Smrz, 2003/01/23
2             #
3             # Encoding of Arabic: ArabTeX Notation by Klaus Lagally #####################################
4              
5             package Encode::Arabic::ArabTeX::RE;
6              
7             our $VERSION = '14.1';
8              
9 2     2   19606 use 5.008;
  2         4  
  2         65  
10              
11 2     2   7 use strict;
  2         2  
  2         55  
12 2     2   9 use warnings;
  2         5  
  2         59  
13              
14 2     2   8 use Scalar::Util 'blessed';
  2         2  
  2         148  
15              
16 2     2   484 use Encode::Encoding;
  2         8433  
  2         69  
17 2     2   10 use base 'Encode::Encoding';
  2         2  
  2         1506  
18              
19             __PACKAGE__->Define('ArabTeX-RE');
20              
21              
22             our (%encode_used, %decode_used, @shams, @qamar);
23              
24             our $enmode;
25             our $demode;
26              
27             our %modemap = (
28              
29             'default' => 3,
30             'undef' => 0,
31              
32             'fullvocalize' => 4,
33             'full' => 4,
34              
35             'vocalize' => 3,
36             'nosukuun' => 3,
37              
38             'novocalize' => 2,
39             'novowels' => 2,
40             'none' => 2,
41              
42             'noshadda' => 1,
43             'noneplus' => 1,
44             );
45              
46              
47             sub import { # perform import as if Encode were used one level before this module
48 2     2   16 require Encode;
49 2 100       34 push @Encode::ISA, 'Exporter' unless Encode->can('export_to_level');
50 2         265 Encode->export_to_level(1, @_);
51             }
52              
53              
54             sub encode ($$;$) {
55 0     0 1   my ($cls, $text, $check) = @_;
56              
57 0 0         $_[1] = '' if $check; # this is what in-place edit needs
58              
59 0 0         $cls->initialize_encode() unless %encode_used;
60              
61 0 0         $text = join '', map { exists $encode_used{$_} ? $encode_used{$_} : $_ } split '', $text;
  0            
62              
63 0           $text =~ s/([\_\.\^]?\w)\\shadda{}/$1$1/g;
64 0           $text =~ s/(\\ham{.})\\shadda{}/$1$1/g;
65              
66 0           $text =~ s/([\=\s\-\%])\\alif{}\\vow{a}l/$1"al-/g;
67 0           $text =~ s/([\=\s\-\%])\\alif{}l/$1al-/g;
68 0           $text =~ s/(b\\vow{i})\\alif{}l/$1-al-/g;
69 0           $text =~ s/([\=\s\-\%])\\alif{}\\vow{([ui])}/$1"$2/g;
70 0           $text =~ s/([\=\s\-\%])\\alif{}/$1i/g;
71 0           $text =~ s/(\\vow{aN})\\alif{}/$1/g;
72 0           $text =~ s/\\alif{}(\\vow{aN})/$1/g;
73 0           $text =~ s/\\vow{a}\\alif{}/\\vow{A}/g;
74 0           $text =~ s/\\alif{}/\\aux{A}/g;
75              
76 0           $text =~ s/\\madda{}/'A/g;
77              
78 0           $text =~ s/\\vow{a}\\maq{}/\\vow{Y}/g;
79 0           $text =~ s/\\maq{}(\\vow{aN})/\\vow{aNY}/g;
80 0           $text =~ s/\\vow{aN}\\maq{}/\\vow{aNY}/g;
81 0           $text =~ s/\\maq{}/\\aux{Y}/g;
82              
83 0           $text =~ s/i(}?)y([^aiuAIUY])/I$1$2/g; # produces \ham{I}, too
84 0           $text =~ s/u(}?)w([^aiuAIUY])/U$1$2/g;
85              
86 0           $text =~ s/([iIuU]})(\\ham{a})/$1-$2/g;
87 0           $text =~ s/([\-\s])\\ham{a}([^\\])/$1'\\aux{a}$2/g;
88 0           $text =~ s/([^\}\s])\\ham{a}/$1\\aux{a}'/g;
89              
90 0           $text =~ s/([^\-\s])(\\ham{i})/$1-$2/g;
91 0           $text =~ s/\\ham{i}([^\\])/'\\aux{i}$1/g;
92              
93 0           $text =~ s/([^\}])(\\ham{w})/$1\\aux{u}$2/g;
94 0           $text =~ s/(\\ham{w})([^\\])/$1\\aux{u}$2/g;
95              
96 0           $text =~ s/([^\}])(\\ham{y})/$1\\aux{i}$2/g;
97 0           $text =~ s/(\\ham{y})([^\\])/$1\\aux{i}$2/g;
98              
99 0           $text =~ s/\\ham{[aiwy]}/'/g;
100 0           $text =~ s/\\ham{I}/'I/g;
101              
102 0           $text =~ s/(?
103              
104              
105 2     2   11 no strict 'refs';
  2         2  
  2         3602  
106              
107 0 0 0       if (defined ${ $cls . '::enmode' } and ${ $cls . '::enmode' } == 3) {
  0 0 0        
  0 0 0        
  0            
108              
109 0           $text =~ s/\\vow{(.+?)}/$1/g;
110 0           $text =~ s/\\aux{(.+?)}/"$1/g;
111 0           $text =~ s/\\sukun{}/"/g;
112             }
113 0           elsif (defined ${ $cls . '::enmode' } and ${ $cls . '::enmode' } == 2) {
  0            
114              
115 0           $text =~ s/\\vow{(.+?)}/"$1/g;
116 0           $text =~ s/\\aux{(.+?)}/$1/g;
117 0           $text =~ s/\\sukun{}/"/g;
118             }
119 0           elsif (defined ${ $cls . '::enmode' } and ${ $cls . '::enmode' } == 4) {
120              
121 0           $text =~ s/\\vow{(.+?)}/$1/g;
122 0           $text =~ s/\\aux{(.+?)}/$1/g;
123 0           $text =~ s/\\sukun{}//g;
124             }
125              
126 0 0         $text = Encode::encode "utf8", $text if Encode::is_utf8($text);
127              
128 0           return $text;
129             }
130              
131              
132             sub decode ($$;$) {
133 0     0 1   my ($cls, $text, $check) = @_;
134 0           my $one;
135              
136 0 0         $_[1] = '' if $check; # this is what in-place edit needs
137              
138 0 0         $text = Encode::decode "utf8", $text unless Encode::is_utf8($text);
139              
140 0 0         $cls->initialize_decode() unless %decode_used;
141              
142 0           $text = "\n" . $text . "\n";
143              
144 0           $text =~ s/_a/a/g; # is there any special character for the defective fatha?
145 0           $text =~ s/_U/U/g; # _U only affects the pronunciation, not the spelling
146              
147 0           foreach $one (@shams, '\\\'', @qamar) {
148              
149 0           $text =~ s/(?
150 0           $text =~ s/(?
151             # alas! using $one in the replacing expression produces extra \\
152             }
153              
154 0           $text =~ s/([\s\-])([aiu])/$1\\L{}$2/gs;
155              
156 0           $text =~ s/([\s\-])'([auUY])/$1\\H{a}$2/gs;
157 0           $text =~ s/([\s\-])'([iI])/$1\\H{i}$2/gs;
158 0           $text =~ s/([\s\-])'A/$1\\M{}/gs;
159              
160 0           $text =~ s/(I|y\\O{})'(aN[AY]?[\s\-])/$1\\H{y}$2/gs;
161 0           $text =~ s/a'(|\\D{})(|[au]N?)([\s\-])/a\\H{a}$1$2$3/gs;
162 0           $text =~ s/a'(|\\D{})(iN?)([\s\-])/a\\H{i}$1$2$3/gs;
163 0           $text =~ s/i'(|\\D{})(|[aiu]N?)([\s\-])/i\\H{y}$1$2$3/gs;
164 0           $text =~ s/u'(|\\D{})(|[aiu]N?)([\s\-])/u\\H{w}$1$2$3/gs;
165 0           $text =~ s/'(|\\D{})(|[aiu]N?)([\s\-])/\\H{}$1$2$3/gs;
166              
167 0           $text =~ s/([iI]|y\\O{})'(|\\D{})/$1\\H{y}$2/g;
168 0           $text =~ s/'(|\\D{})([iI])/\\H{y}$1$2/g;
169 0           $text =~ s/([uU])'(|\\D{})/$1\\H{w}$2/g;
170 0           $text =~ s/'(|\\D{})([uU])/\\H{w}$1$2/g;
171 0           $text =~ s/A'(|\\D{})/A\\H{}$1/g; # how do you write ?
172 0           $text =~ s/a'(\\D{})/a\\H{a}$1/g; # how do you write ?
173 0           $text =~ s/'A/\\M{}/g;
174 0           $text =~ s/'a/\\H{a}a/g;
175 0           $text =~ s/'Y/\\H{a}Y/g;
176              
177 0           $text =~ s/'/\\H{a}a/g; # final resort
178              
179 0           foreach $one (@shams) { $text =~ s/($one)\-$one/l$1\\D{}/g; }
  0            
180 0           foreach $one ('\\\\', @qamar) { $text =~ s/l\-($one)/l\\O{}$1/g; }
  0            
181             # alas! using $one in the replacing expression produces extra \\
182              
183 0           $text =~ s/aNY/\\V{aN}\\Q{}/g;
184 0           $text =~ s/(?<=A\\H{}|\\H{a})aN/\\V{aN}/g;
185 0           $text =~ s/(?<=T)aN/\\V{aN}/g;
186              
187 0           $text =~ s/(?
188 0           $text =~ s/(?
189 0           $text =~ s/(?
190              
191 0           $text =~ s/UA/\\V{u}w\\L{}/g;
192 0           $text =~ s/aWA?/\\V{a}w\\O{}\\L{}/g;
193              
194 0           $text =~ s/([^{])a/$1\\V{a}/g;
195 0           $text =~ s/([^{])i/$1\\V{i}/g;
196 0           $text =~ s/([^{])u/$1\\V{u}/g;
197              
198 0           $text =~ s/A/\\V{a}\\L{}/g;
199 0           $text =~ s/Iy/\\V{i}y\\D{}/g;
200 0           $text =~ s/I/\\V{i}y/g;
201 0           $text =~ s/Uw/\\V{u}w\\D{}/g;
202 0           $text =~ s/U/\\V{u}w/g;
203 0           $text =~ s/Y/\\V{a}\\Q{}/g;
204              
205 0           $text =~ s/\-//g;
206              
207 0           $text =~ s/l((\\V\{[aiu]\}|\\D\{\}|\\O\{\})+)(\\L\{\}|\\H\{[ai]\}|\\M\{\})/l$3$1/g;
208              
209 0           foreach $one (keys %decode_used) { # risky .. the order matters and negative lookahead \{ is just right
210              
211 0           while ($text =~ s/(?
212             }
213              
214 0           $text = substr $text, 1, -1; # remove additional "\n"s
215              
216 0           return $text;
217             }
218              
219              
220             sub initialize_encode ($) {
221 0     0 0   my $cls = shift @_;
222              
223 0           %encode_used = (
224             # "p", # 81 #"\201",
225             # "^c", # 8D #"\215",
226             # "^z", # 8E #"\216",
227             # "\217", # 8F #"\217",
228             # "g", # 90 #"\220",
229             "\x{060C}", ",", # A1 "\241", '\\,', # 161 "\xA1", # "\xD8\x8C" right-to-left-comma
230             # "\\lq ", # AB #"\253",
231             "\x{061B}", ";", # BA "\272", '\\;', # 186 "\xBA", # "\xD8\x9B" right-to-left-semicolon
232             # "\\rq", # BB #"\273",
233             "\x{061F}", "?", # BF "\277", '\\?', # 191 "\xBF", # "\xD8\x9F" right-to-left-question-mark
234             "\x{0621}", "'", # C1 "\301", '\\\\H{}', # 193 "\xC1", # "\xD8\xA1" hamza-on-the-line
235             "\x{0622}", "\\madda{}", # C2 "\302", '\\\\M{}', # 194 "\xC2", # "\xD8\xA2" madda-over-'alif
236             "\x{0623}", "\\ham{a}", # C3 "\303", '\\\\H{a}', # 195 "\xC3", # "\xD8\xA3" hamza-over-'alif
237             "\x{0624}", "\\ham{w}", # C4 "\304", '\\\\H{w}', # 196 "\xC4", # "\xD8\xA4" hamza-over-waaw
238             "\x{0625}", "\\ham{i}", # C5 "\305", '\\\\H{i}', # 197 "\xC5", # "\xD8\xA5" hamza-under-'alif
239             "\x{0626}", "\\ham{y}", # C6 "\306", '\\\\H{y}', # 198 "\xC6", # "\xD8\xA6" hamza-over-yaa'
240             "\x{0627}", "\\alif{}", # C7 "\307", '\\\\L{}', # 199 "\xC7", # "\xD8\xA7" bare 'alif
241             "\x{0628}", "b", # C8 "\310", 'b', # 200 "\xC8", # "\xD8\xA8"
242             "\x{0629}", "T", # C9 "\311", 'T', # 201 "\xC9", # "\xD8\xA9"
243             "\x{062A}", "t", # CA "\312", 't', # 202 "\xCA", # "\xD8\xAA"
244             "\x{062B}", "_t", # CB "\313", '\\_t', # 203 "\xCB", # "\xD8\xAB" <_t>
245             "\x{062C}", "^g", # CC "\314", '\\^g', # 204 "\xCC", # "\xD8\xAC" <^g>
246             "\x{062D}", ".h", # CD "\315", '\\.h', # 205 "\xCD", # "\xD8\xAD" <.h>
247             "\x{062E}", "_h", # CE "\316", '\\_h', # 206 "\xCE", # "\xD8\xAE" <_h>
248             "\x{062F}", "d", # CF "\317", 'd', # 207 "\xCF", # "\xD8\xAF"
249             "\x{0630}", "_d", # D0 "\320", '\\_d', # 208 "\xD0", # "\xD8\xB0" <_d>
250             "\x{0631}", "r", # D1 "\321", 'r', # 209 "\xD1", # "\xD8\xB1"
251             "\x{0632}", "z", # D2 "\322", 'z', # 210 "\xD2", # "\xD8\xB2"
252             "\x{0633}", "s", # D3 "\323", 's', # 211 "\xD3", # "\xD8\xB3"
253             "\x{0634}", "^s", # D4 "\324", '\\^s', # 212 "\xD4", # "\xD8\xB4" <^s>
254             "\x{0635}", ".s", # D5 "\325", '\\.s', # 213 "\xD5", # "\xD8\xB5" <.s>
255             "\x{0636}", ".d", # D6 "\326", '\\.d', # 214 "\xD6", # "\xD8\xB6" <.d>
256             # "\327", # D7 #"\327",
257             "\x{0637}", ".t", # D8 "\330", '\\.t', # 216 "\xD8", # "\xD8\xB7" <.t>
258             "\x{0638}", ".z", # D9 "\331", '\\.z', # 217 "\xD9", # "\xD8\xB8" <.z>
259             "\x{0639}", "`", # DA "\332", '\\`', # 218 "\xDA", # "\xD8\xB9" <`>
260             "\x{063A}", ".g", # DB "\333", '\\.g', # 219 "\xDB", # "\xD8\xBA" <.g>
261             "\x{0640}", "-", # DC "\334", '--', # 220 "\xDC", # "\xD9\x80" ta.twiil
262             "\x{0641}", "f", # DD "\335", 'f', # 221 "\xDD", # "\xD9\x81"
263             "\x{0642}", "q", # DE "\336", 'q', # 222 "\xDE", # "\xD9\x82"
264             "\x{0643}", "k", # DF "\337", 'k', # 223 "\xDF", # "\xD9\x83"
265             # "\340", # E0 #"\340",
266             "\x{0644}", "l", # E1 "\341", 'l', # 225 "\xE1", # "\xD9\x84"
267             # "\342", # E2 #"\342",
268             "\x{0645}", "m", # E3 "\343", 'm', # 227 "\xE3", # "\xD9\x85"
269             "\x{0646}", "n", # E4 "\344", 'n', # 228 "\xE4", # "\xD9\x86"
270             "\x{0647}", "h", # E5 "\345", 'h', # 229 "\xE5", # "\xD9\x87"
271             "\x{0648}", "w", # E6 "\346", 'w', # 230 "\xE6", # "\xD9\x88"
272             "\x{0649}", "\\maq{}", # EC "\354", '\\\\Q{}', # 236 "\xEC", # "\xD9\x89" 'alif maq.suura
273             "\x{064A}", "y", # ED "\355", 'y', # 237 "\xED", # "\xD9\x8A"
274             "\x{064B}", "\\vow{aN}", # F0 "\360", '\\\\V{aN}', # 240 "\xF0", # "\xD9\x8B"
275             "\x{064C}", "\\vow{uN}", # F1 "\361", '\\\\V{uN}', # 241 "\xF1", # "\xD9\x8C"
276             "\x{064D}", "\\vow{iN}", # F2 "\362", '\\\\V{iN}', # 242 "\xF2", # "\xD9\x8D"
277             "\x{064E}", "\\vow{a}", # F3 "\363", '\\\\V{a}', # 243 "\xF3", # "\xD9\x8E"
278             "\x{064F}", "\\vow{u}", # F5 "\365", '\\\\V{u}', # 245 "\xF5", # "\xD9\x8F"
279             "\x{0650}", "\\vow{i}", # F6 "\366", '\\\\V{i}', # 246 "\xF6", # "\xD9\x90"
280             "\x{0651}", "\\shadda{}", # F8 "\370", '\\\\D{}', # 248 "\xF8", # "\xD9\x91" ^sadda
281             "\x{0652}", "\\sukun{}", # FA "\372", '\\\\O{}', # 250 "\xFA", # "\xD9\x92" sukuun
282             "\x{0670}", # '\\\\A{}', # 243 "\xF3", # "\xD9\xB0" <_a> ->
283             "\x{0671}", # '\\\\W{}', # 199 "\xC7", # "\xD9\xB1" wa.sla-on-'alif -> bare 'alif
284             );
285              
286              
287 2     2   13 no strict 'refs';
  2         3  
  2         866  
288              
289 0 0         $cls->enmode(defined ${ $cls . '::enmode' } ? ${ $cls . '::enmode' } : 'default');
  0            
  0            
290             }
291              
292              
293             sub initialize_decode ($) {
294 0     0 0   my $cls = shift @_;
295              
296 0           @shams = ('t', '\\_t', 'd', '\\_d', 'r', 'z', 's', '\\^s', '\\.s', '\\.d', '\\.t', '\\.z', 'l', 'n');
297 0           @qamar = ('b', '\\^g', '\\.h', '\\_h', '\\`', '\\.g', 'f', 'q', 'k', 'm', 'h', 'w', 'y');
298              
299 0           %decode_used = (
300             # 'p', # 129 "\x81",
301             # '\\^c', # 141 "\x8D",
302             # '\\^z', # 142 "\x8E",
303             # 'g', # 144 "\x90",
304             '\\,', "\x{060C}", # 161 "\xA1", # "\xD8\x8C" right-to-left-comma
305             '\\;', "\x{061B}", # 186 "\xBA", # "\xD8\x9B" right-to-left-semicolon
306             '\\?', "\x{061F}", # 191 "\xBF", # "\xD8\x9F" right-to-left-question-mark
307             '\\\\H{}', "\x{0621}", # 193 "\xC1", # "\xD8\xA1" hamza-on-the-line
308             '\\\\M{}', "\x{0622}", # 194 "\xC2", # "\xD8\xA2" madda-over-'alif
309             '\\\\H{a}', "\x{0623}", # 195 "\xC3", # "\xD8\xA3" hamza-over-'alif
310             '\\\\H{w}', "\x{0624}", # 196 "\xC4", # "\xD8\xA4" hamza-over-waaw
311             '\\\\H{i}', "\x{0625}", # 197 "\xC5", # "\xD8\xA5" hamza-under-'alif
312             '\\\\H{y}', "\x{0626}", # 198 "\xC6", # "\xD8\xA6" hamza-over-yaa'
313             '\\\\L{}', "\x{0627}", # 199 "\xC7", # "\xD8\xA7" bare 'alif
314             'b', "\x{0628}", # 200 "\xC8", # "\xD8\xA8"
315             'T', "\x{0629}", # 201 "\xC9", # "\xD8\xA9"
316             't', "\x{062A}", # 202 "\xCA", # "\xD8\xAA"
317             '\\_t', "\x{062B}", # 203 "\xCB", # "\xD8\xAB" <_t>
318             '\\^g', "\x{062C}", # 204 "\xCC", # "\xD8\xAC" <^g>
319             '\\.h', "\x{062D}", # 205 "\xCD", # "\xD8\xAD" <.h>
320             '\\_h', "\x{062E}", # 206 "\xCE", # "\xD8\xAE" <_h>
321             'd', "\x{062F}", # 207 "\xCF", # "\xD8\xAF"
322             '\\_d', "\x{0630}", # 208 "\xD0", # "\xD8\xB0" <_d>
323             'r', "\x{0631}", # 209 "\xD1", # "\xD8\xB1"
324             'z', "\x{0632}", # 210 "\xD2", # "\xD8\xB2"
325             's', "\x{0633}", # 211 "\xD3", # "\xD8\xB3"
326             '\\^s', "\x{0634}", # 212 "\xD4", # "\xD8\xB4" <^s>
327             '\\.s', "\x{0635}", # 213 "\xD5", # "\xD8\xB5" <.s>
328             '\\.d', "\x{0636}", # 214 "\xD6", # "\xD8\xB6" <.d>
329             '\\.t', "\x{0637}", # 216 "\xD8", # "\xD8\xB7" <.t>
330             '\\.z', "\x{0638}", # 217 "\xD9", # "\xD8\xB8" <.z>
331             '\\`', "\x{0639}", # 218 "\xDA", # "\xD8\xB9" <`>
332             '\\.g', "\x{063A}", # 219 "\xDB", # "\xD8\xBA" <.g>
333             '--', "\x{0640}", # 220 "\xDC", # "\xD9\x80" ta.twiil
334             'f', "\x{0641}", # 221 "\xDD", # "\xD9\x81"
335             'q', "\x{0642}", # 222 "\xDE", # "\xD9\x82"
336             'k', "\x{0643}", # 223 "\xDF", # "\xD9\x83"
337             'l', "\x{0644}", # 225 "\xE1", # "\xD9\x84"
338             'm', "\x{0645}", # 227 "\xE3", # "\xD9\x85"
339             'n', "\x{0646}", # 228 "\xE4", # "\xD9\x86"
340             'h', "\x{0647}", # 229 "\xE5", # "\xD9\x87"
341             'w', "\x{0648}", # 230 "\xE6", # "\xD9\x88"
342             '\\\\Q{}', "\x{0649}", # 236 "\xEC", # "\xD9\x89" 'alif maq.suura
343             'y', "\x{064A}", # 237 "\xED", # "\xD9\x8A"
344             '\\\\V{aN}', "\x{064B}", # 240 "\xF0", # "\xD9\x8B"
345             '\\\\V{uN}', "\x{064C}", # 241 "\xF1", # "\xD9\x8C"
346             '\\\\V{iN}', "\x{064D}", # 242 "\xF2", # "\xD9\x8D"
347             '\\\\V{a}', "\x{064E}", # 243 "\xF3", # "\xD9\x8E"
348             '\\\\V{u}', "\x{064F}", # 245 "\xF5", # "\xD9\x8F"
349             '\\\\V{i}', "\x{0650}", # 246 "\xF6", # "\xD9\x90"
350             '\\\\D{}', "\x{0651}", # 248 "\xF8", # "\xD9\x91" ^sadda
351             '\\\\O{}', "\x{0652}", # 250 "\xFA", # "\xD9\x92" sukuun
352             '\\\\A{}', "\x{0670}", # 243 "\xF3", # "\xD9\xB0" <_a> ->
353             '\\\\W{}', "\x{0671}", # 199 "\xC7", # "\xD9\xB1" wa.sla-on-'alif -> bare 'alif
354             );
355              
356              
357 2     2   12 no strict 'refs';
  2         3  
  2         303  
358              
359 0 0         $cls->demode(defined ${ $cls . '::demode' } ? ${ $cls . '::demode' } : 'default');
  0            
  0            
360             }
361              
362              
363             sub enmode ($$) {
364 0     0 0   my ($cls, $mode) = @_;
365              
366 0 0         $cls = blessed $cls if ref $cls;
367              
368 0 0         $mode = 'undef' unless defined $mode;
369 0 0         $mode = $modemap{$mode} if exists $modemap{$mode};
370              
371 2     2   11 no strict 'refs';
  2         7  
  2         253  
372              
373 0           my $return = ${ $cls . '::enmode' };
  0            
374              
375 0           ${ $cls . '::enmode' } = $mode;
  0            
376              
377 0           return $return;
378             }
379              
380              
381             sub demode ($$) {
382 0     0 0   my ($cls, $mode) = @_;
383              
384 0 0         $cls = blessed $cls if ref $cls;
385              
386 0 0         $mode = 'undef' unless defined $mode;
387 0 0         $mode = $modemap{$mode} if exists $modemap{$mode};
388              
389 2     2   11 no strict 'refs';
  2         3  
  2         154  
390              
391 0           my $return = ${ $cls . '::demode' };
  0            
392              
393 0           ${ $cls . '::demode' } = $mode;
  0            
394              
395 0           return $return;
396             }
397              
398              
399             1;
400              
401             __END__