line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Data::Visitor::Encode; |
3
|
2
|
|
|
2
|
|
64583
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Encode(); |
5
|
|
|
|
|
|
|
use Scalar::Util (); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends 'Data::Visitor'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.10007'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'visit_method' => ( |
12
|
|
|
|
|
|
|
is => 'rw', |
13
|
|
|
|
|
|
|
isa => 'Str' |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'extra_args' => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
no Moose; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _object { ref $_[0] ? $_[0] : $_[0]->new } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub visit_glob |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
return $_[1]; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub visit_scalar |
32
|
|
|
|
|
|
|
{ |
33
|
|
|
|
|
|
|
my ($self, $ref) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $ret = $self->visit_value($$ref); |
36
|
|
|
|
|
|
|
if (defined $ret) { |
37
|
|
|
|
|
|
|
return \$ret; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
return undef; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# We care about the hash key as well, so override |
43
|
|
|
|
|
|
|
sub visit_hash |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
my ($self, $hash) = @_; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my %map = map { |
48
|
|
|
|
|
|
|
( |
49
|
|
|
|
|
|
|
$self->visit_value($_), |
50
|
|
|
|
|
|
|
$self->visit($hash->{$_}) |
51
|
|
|
|
|
|
|
) |
52
|
|
|
|
|
|
|
} keys %$hash; |
53
|
|
|
|
|
|
|
return \%map; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub visit_object |
57
|
|
|
|
|
|
|
{ |
58
|
|
|
|
|
|
|
my ($self, $data) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $type = lc (Scalar::Util::reftype($data)); |
61
|
|
|
|
|
|
|
my $method = "visit_$type"; |
62
|
|
|
|
|
|
|
my $ret = $self->$method($data); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return bless $ret, Scalar::Util::blessed($data); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub visit_value |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
my ($self, $data) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# return as-is if undefined |
72
|
|
|
|
|
|
|
return $data unless defined $data; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# return as-is if no method |
75
|
|
|
|
|
|
|
my $method = $self->visit_method(); |
76
|
|
|
|
|
|
|
return $data unless $method; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# return if unimplemented |
79
|
|
|
|
|
|
|
$method = "do_$method"; |
80
|
|
|
|
|
|
|
# return $data if (! $self->can($method)); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
return $self->$method($data); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub do_utf8_on |
86
|
|
|
|
|
|
|
{ |
87
|
|
|
|
|
|
|
my $self = shift; |
88
|
|
|
|
|
|
|
my $data = shift; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Encode::_utf8_on($data); |
91
|
|
|
|
|
|
|
return $data; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub do_utf8_off |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
my $self = shift; |
97
|
|
|
|
|
|
|
my $data = shift; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Encode::_utf8_off($data); |
100
|
|
|
|
|
|
|
return $data; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub utf8_on |
104
|
|
|
|
|
|
|
{ |
105
|
|
|
|
|
|
|
my $self = _object(shift); |
106
|
|
|
|
|
|
|
$self->visit_method('utf8_on'); |
107
|
|
|
|
|
|
|
$self->visit($_[0]); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub utf8_off |
111
|
|
|
|
|
|
|
{ |
112
|
|
|
|
|
|
|
my $self = _object(shift); |
113
|
|
|
|
|
|
|
$self->visit_method('utf8_off'); |
114
|
|
|
|
|
|
|
$self->visit($_[0]); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub do_encode { |
118
|
|
|
|
|
|
|
my $self = shift; |
119
|
|
|
|
|
|
|
return $_[0] = $self->{__encoding}->encode($_[0]); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub do_decode { |
123
|
|
|
|
|
|
|
my $self = shift; |
124
|
|
|
|
|
|
|
return $_[0] = $self->{__encoding}->decode($_[0]); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub decode |
128
|
|
|
|
|
|
|
{ |
129
|
|
|
|
|
|
|
my $self = _object(shift); |
130
|
|
|
|
|
|
|
my $code = shift; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my $encoding = Encode::find_encoding( $code ); |
133
|
|
|
|
|
|
|
if (! $encoding) { |
134
|
|
|
|
|
|
|
Carp::confess("Could not find encoding by the name of $encoding"); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
local $self->{__encoding} = $encoding; |
137
|
|
|
|
|
|
|
$self->extra_args($code); |
138
|
|
|
|
|
|
|
$self->visit_method('decode'); |
139
|
|
|
|
|
|
|
$_[0] = $self->visit($_[0]); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub encode |
143
|
|
|
|
|
|
|
{ |
144
|
|
|
|
|
|
|
my $self = _object(shift); |
145
|
|
|
|
|
|
|
my $code = shift; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my $encoding = Encode::find_encoding( $code ); |
148
|
|
|
|
|
|
|
if (! $encoding) { |
149
|
|
|
|
|
|
|
Carp::confess("Could not find encoding by the name of $encoding"); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
local $self->{__encoding} = $encoding; |
152
|
|
|
|
|
|
|
$self->extra_args($code); |
153
|
|
|
|
|
|
|
$self->visit_method('encode'); |
154
|
|
|
|
|
|
|
$_[0] = $self->visit($_[0]); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub do_decode_utf8 { |
158
|
|
|
|
|
|
|
my $self = shift; |
159
|
|
|
|
|
|
|
return $_[0] = Encode::decode_utf8($_[0]); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub decode_utf8 |
163
|
|
|
|
|
|
|
{ |
164
|
|
|
|
|
|
|
my $self = _object(shift); |
165
|
|
|
|
|
|
|
$self->visit_method('decode_utf8'); |
166
|
|
|
|
|
|
|
$_[0] = $self->visit($_[0]); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub do_encode_utf8 |
170
|
|
|
|
|
|
|
{ |
171
|
|
|
|
|
|
|
my $self = shift; |
172
|
|
|
|
|
|
|
return $_[0] = Encode::encode_utf8($_[0]); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub encode_utf8 |
176
|
|
|
|
|
|
|
{ |
177
|
|
|
|
|
|
|
my $self = _object(shift); |
178
|
|
|
|
|
|
|
my $enc = $_[1]; |
179
|
|
|
|
|
|
|
$self->visit_method('encode_utf8'); |
180
|
|
|
|
|
|
|
$_[0] = $self->visit($_[0]); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub do_h2z |
184
|
|
|
|
|
|
|
{ |
185
|
|
|
|
|
|
|
my $self = shift; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
my $is_euc = ($self->extra_args =~ /^euc-jp$/i); |
188
|
|
|
|
|
|
|
my $utf8_on = Encode::is_utf8($_[0]); |
189
|
|
|
|
|
|
|
my $euc_encoding = $self->{__euc}; |
190
|
|
|
|
|
|
|
my $encoding = $self->{__encoding}; |
191
|
|
|
|
|
|
|
my $euc = |
192
|
|
|
|
|
|
|
$is_euc ? |
193
|
|
|
|
|
|
|
$_[0] : |
194
|
|
|
|
|
|
|
$utf8_on ? |
195
|
|
|
|
|
|
|
$euc_encoding->encode($_[0]) : |
196
|
|
|
|
|
|
|
$euc_encoding->encode($encoding->decode($_[0])) |
197
|
|
|
|
|
|
|
; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Encode::JP::H2Z::h2z(\$euc); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
return $_[0] = ( |
202
|
|
|
|
|
|
|
$is_euc ? |
203
|
|
|
|
|
|
|
$euc : |
204
|
|
|
|
|
|
|
$utf8_on ? |
205
|
|
|
|
|
|
|
$euc_encoding->decode($euc) : |
206
|
|
|
|
|
|
|
$encoding->encode($euc_encoding->decode($euc)) |
207
|
|
|
|
|
|
|
); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub h2z |
211
|
|
|
|
|
|
|
{ |
212
|
|
|
|
|
|
|
my $self = _object(shift); |
213
|
|
|
|
|
|
|
my $code = shift; |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
require Encode::JP::H2Z; |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
local $self->{__euc} = Encode::find_encoding('euc-jp'); |
218
|
|
|
|
|
|
|
my $encoding = Encode::find_encoding( $code ); |
219
|
|
|
|
|
|
|
if (! $encoding) { |
220
|
|
|
|
|
|
|
Carp::confess("Could not find encoding by the name of $encoding"); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
local $self->{__encoding} = $encoding; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
$self->visit_method('h2z'); |
225
|
|
|
|
|
|
|
$self->extra_args($code); |
226
|
|
|
|
|
|
|
$self->visit($_[0]); |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub do_z2h |
230
|
|
|
|
|
|
|
{ |
231
|
|
|
|
|
|
|
my $self = shift; |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
my $is_euc = ($self->extra_args =~ /^euc-jp$/i); |
234
|
|
|
|
|
|
|
my $utf8_on = Encode::is_utf8($_[0]); |
235
|
|
|
|
|
|
|
my $euc_encoding = $self->{__euc}; |
236
|
|
|
|
|
|
|
my $encoding = $self->{__encoding}; |
237
|
|
|
|
|
|
|
my $euc = |
238
|
|
|
|
|
|
|
$is_euc ? |
239
|
|
|
|
|
|
|
$_[0] : |
240
|
|
|
|
|
|
|
$utf8_on ? |
241
|
|
|
|
|
|
|
$euc_encoding->encode($_[0]) : |
242
|
|
|
|
|
|
|
$euc_encoding->encode($encoding->decode($_[0])) |
243
|
|
|
|
|
|
|
; |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Encode::JP::H2Z::z2h(\$euc); |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
return $_[0] = ( |
248
|
|
|
|
|
|
|
$is_euc ? |
249
|
|
|
|
|
|
|
$euc : |
250
|
|
|
|
|
|
|
$utf8_on ? |
251
|
|
|
|
|
|
|
$euc_encoding->decode($euc) : |
252
|
|
|
|
|
|
|
$encoding->encode($euc_encoding->decode($euc)) |
253
|
|
|
|
|
|
|
); |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub z2h |
257
|
|
|
|
|
|
|
{ |
258
|
|
|
|
|
|
|
my $self = _object(shift); |
259
|
|
|
|
|
|
|
my $code = shift; |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
require Encode::JP::H2Z; |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
local $self->{__euc} = Encode::find_encoding('euc-jp'); |
264
|
|
|
|
|
|
|
my $encoding = Encode::find_encoding( $code ); |
265
|
|
|
|
|
|
|
if (! $encoding) { |
266
|
|
|
|
|
|
|
Carp::confess("Could not find encoding by the name of $encoding"); |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
local $self->{__encoding} = $encoding; |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
$self->visit_method('z2h'); |
271
|
|
|
|
|
|
|
$self->extra_args($code); |
272
|
|
|
|
|
|
|
$self->visit($_[0]); |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
1; |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
__END__ |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head1 NAME |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Data::Visitor::Encode - Encode/Decode Values In A Structure (DEPRECATED) |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=head1 SYNOPSIS |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
# THIS MODULE IS NOW DEPRECATED. Use Data::Recursive::Encode instead |
286
|
|
|
|
|
|
|
use Data::Visitor::Encode; |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
my $dev = Data::Visitor::Encode->new(); |
289
|
|
|
|
|
|
|
my %hash = (...); # assume data is in Perl native Unicode |
290
|
|
|
|
|
|
|
$dev->encode('euc-jp', \%hash); # now strings are in euc-jp |
291
|
|
|
|
|
|
|
$dev->decode('euc-jp', \%hash); # now strings are back in unicode |
292
|
|
|
|
|
|
|
$dev->utf8_on(\%hash); |
293
|
|
|
|
|
|
|
$dev->utf8_off(\%hash); |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 DEPRECATION ALERT |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
This module has been DEPRECATED in favor of L<Data::Recursive::Encode>. Bug reports will not be acted upon, and the module will cease to exist from CPAN by the end of year 2011. |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
You've been warned (since 2009) |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=head1 DESCRIPTION |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
Data::Visitor::Encode visits each node of a structure, and returns a new |
304
|
|
|
|
|
|
|
structure with each node's encoding (or similar action). If you ever wished |
305
|
|
|
|
|
|
|
to do a bulk encode/decode of the contents of a structure, then this |
306
|
|
|
|
|
|
|
module may help you. |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
Starting from 0.09000, you can directly use the methods without instantiating |
309
|
|
|
|
|
|
|
the object: |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
Data::Visitor::Encode->encode('euc-jp', $obj); |
312
|
|
|
|
|
|
|
# instead of Data::Visitor::Encode->new->encod('euc-jp', $obj) |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=head1 METHODS |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=head2 utf8_on |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
$dev->utf8_on(\%hash); |
319
|
|
|
|
|
|
|
$dev->utf8_on(\@list); |
320
|
|
|
|
|
|
|
$dev->utf8_on(\$scalar); |
321
|
|
|
|
|
|
|
$dev->utf8_on($scalar); |
322
|
|
|
|
|
|
|
$dev->utf8_on($object); |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
Returns a structure containing nodes with utf8 flag on |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
=head2 utf8_off |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
$dev->utf8_off(\%hash); |
329
|
|
|
|
|
|
|
$dev->utf8_off(\@list); |
330
|
|
|
|
|
|
|
$dev->utf8_off(\$scalar); |
331
|
|
|
|
|
|
|
$dev->utf8_off($scalar); |
332
|
|
|
|
|
|
|
$dev->utf8_off($object); |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
Returns a structure containing nodes with utf8 flag off |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
=head2 encode |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
$dev->encode($encoding, \%hash [, CHECK]); |
339
|
|
|
|
|
|
|
$dev->encode($encoding, \@list [, CHECK]); |
340
|
|
|
|
|
|
|
$dev->encode($encoding, \$scalar [, CHECK]); |
341
|
|
|
|
|
|
|
$dev->encode($encoding, $scalar [, CHECK]); |
342
|
|
|
|
|
|
|
$dev->encode($encoding, $object [, CHECK]); |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
Returns a structure containing nodes which are encoded in the specified |
345
|
|
|
|
|
|
|
encoding. |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=head2 decode |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
$dev->decode($encoding, \%hash); |
350
|
|
|
|
|
|
|
$dev->decode($encoding, \@list); |
351
|
|
|
|
|
|
|
$dev->decode($encoding, \$scalar); |
352
|
|
|
|
|
|
|
$dev->decode($encoding, $scalar); |
353
|
|
|
|
|
|
|
$dev->decode($encoding, $object); |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
Returns a structure containing nodes which are decoded from the specified |
356
|
|
|
|
|
|
|
encoding. |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
=head2 decode_utf8 |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
$dev->decode_utf8(\%hash); |
361
|
|
|
|
|
|
|
$dev->decode_utf8(\@list); |
362
|
|
|
|
|
|
|
$dev->decode_utf8(\$scalar); |
363
|
|
|
|
|
|
|
$dev->decode_utf8($scalar); |
364
|
|
|
|
|
|
|
$dev->decode_utf8($object); |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
Returns a structure containing nodes which have been processed through |
367
|
|
|
|
|
|
|
decode_utf8. |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
=head2 encode_utf8 |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
$dev->encode_utf8(\%hash); |
372
|
|
|
|
|
|
|
$dev->encode_utf8(\@list); |
373
|
|
|
|
|
|
|
$dev->encode_utf8(\$scalar); |
374
|
|
|
|
|
|
|
$dev->encode_utf8($scalar); |
375
|
|
|
|
|
|
|
$dev->encode_utf8($object); |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
Returns a structure containing nodes which have been processed through |
378
|
|
|
|
|
|
|
encode_utf8. |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
=head2 h2z |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
=head2 z2h |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
$dev->h2z($encoding, \%hash); |
385
|
|
|
|
|
|
|
$dev->h2z($encoding, \@list); |
386
|
|
|
|
|
|
|
$dev->h2z($encoding, \$scalar); |
387
|
|
|
|
|
|
|
$dev->h2z($encoding, $scalar); |
388
|
|
|
|
|
|
|
$dev->h2z($encoding, $object); |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
h2z and z2h are Japanese-only methods (hey, I'm a little biased like that). |
391
|
|
|
|
|
|
|
They perform the task of mapping half-width katakana to full-width katakana |
392
|
|
|
|
|
|
|
and vice-versa. |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
These methods use Encode::JP::H2Z, which requires us to go from the |
395
|
|
|
|
|
|
|
original encoding to euc-jp and then back. There are other modules that are |
396
|
|
|
|
|
|
|
built to handle exactly this problem, which may come out to be faster than |
397
|
|
|
|
|
|
|
using Encode.pm's somewhat hidden Encode::JP::H2Z, but I really don't care |
398
|
|
|
|
|
|
|
for adding another dependency to this module other than Encode.pm, so |
399
|
|
|
|
|
|
|
here it is. |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
If you're significantly worried about performance, I'll gladly accept patches |
402
|
|
|
|
|
|
|
as long as there are no prerequisite modules or the prerequisite is optional. |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
=head2 decode_utf8 |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
$dev->decode_utf8(\%hash); |
407
|
|
|
|
|
|
|
$dev->decode_utf8(\@list); |
408
|
|
|
|
|
|
|
$dev->decode_utf8(\$scalar); |
409
|
|
|
|
|
|
|
$dev->decode_utf8($scalar); |
410
|
|
|
|
|
|
|
$dev->decode_utf8($object); |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
Returns a structure containing nodes which have been processed through |
413
|
|
|
|
|
|
|
decode_utf8. |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
=head2 encode_utf8 |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
$dev->encode_utf8(\%hash); |
418
|
|
|
|
|
|
|
$dev->encode_utf8(\@list); |
419
|
|
|
|
|
|
|
$dev->encode_utf8(\$scalar); |
420
|
|
|
|
|
|
|
$dev->encode_utf8($scalar); |
421
|
|
|
|
|
|
|
$dev->encode_utf8($object); |
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
Returns a structure containing nodes which have been processed through |
424
|
|
|
|
|
|
|
encode_utf8. |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
=head2 do_decode |
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
=head2 do_encode |
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
=head2 do_utf8_off |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
=head2 do_utf8_on |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
=head2 do_h2z |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
=head2 do_z2h |
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
=head2 do_encode_utf8 |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
=head2 do_decode_utf8 |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
=head2 visit_glob |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
=head2 visit_hash |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
=head2 visit_object |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
=head2 visit_scalar |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
=head2 visit_value |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
These methods are private. Only use if it you are subclassing this class. |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
=head1 AUTHOR |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
Copyright (c) 2007 Daisuke Maki E<lt>daisuke@endeworks.jpE<gt> |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
=head1 SEE ALSO |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
L<Data::Visitor|Data::Visitor>, L<Encode|Encode> |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
=head1 LICENSE |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
465
|
|
|
|
|
|
|
under the same terms as Perl itself. |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
See http://www.perl.com/perl/misc/Artistic.html |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
=cut |