1 |
joko |
1.1 |
############################################## |
2 |
|
|
# |
3 |
|
|
# $Id: Common.pm,v 1.1 2002/10/10 03:26:00 cvsjoko Exp $ |
4 |
|
|
# |
5 |
|
|
# $Log: Common.pm,v $ |
6 |
|
|
# Revision 1.1 2002/10/10 03:26:00 cvsjoko |
7 |
|
|
# + new |
8 |
|
|
# |
9 |
|
|
############################################## |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
package Data::Transform::Encode; |
13 |
|
|
|
14 |
|
|
use strict; |
15 |
|
|
use warnings; |
16 |
|
|
|
17 |
|
|
require Exporter; |
18 |
|
|
our @ISA = qw( Exporter ); |
19 |
|
|
our @EXPORT_OK = qw( &var2utf8 &var_utf2iso ); |
20 |
|
|
|
21 |
|
|
use Unicode::String qw(utf8 latin1); |
22 |
|
|
|
23 |
|
|
sub var2utf8 { |
24 |
|
|
my $vref = shift; |
25 |
|
|
if (ref $vref eq 'HASH') { |
26 |
|
|
foreach (keys %{$vref}) { |
27 |
|
|
if ((ref $vref->{$_}) =~ m/ARRAY|HASH/) { |
28 |
|
|
var2utf8($vref->{$_}); |
29 |
|
|
} else { |
30 |
|
|
$vref->{$_} = scalar2utf8($vref->{$_}); |
31 |
|
|
} |
32 |
|
|
} |
33 |
|
|
} elsif (ref $vref eq 'ARRAY') { |
34 |
|
|
foreach (@{$vref}) { |
35 |
|
|
if (ref $_ ne 'SCALAR') { |
36 |
|
|
var2utf8($_); |
37 |
|
|
} else { |
38 |
|
|
$_ = scalar2utf8($_); |
39 |
|
|
} |
40 |
|
|
} |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
sub scalar2utf8 { |
46 |
|
|
my $scalar = shift; |
47 |
|
|
if ($scalar) { |
48 |
|
|
my $u = latin1($scalar); |
49 |
|
|
return $u->utf8; |
50 |
|
|
} |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
sub var_utf2iso { |
54 |
|
|
my $vref = shift; |
55 |
|
|
if (ref $vref eq 'HASH') { |
56 |
|
|
foreach (keys %{$vref}) { |
57 |
|
|
if ((ref $vref->{$_}) =~ m/ARRAY|HASH/) { |
58 |
|
|
var_utf2iso($vref->{$_}); |
59 |
|
|
} else { |
60 |
|
|
$vref->{$_} = scalar2iso($vref->{$_}); |
61 |
|
|
} |
62 |
|
|
} |
63 |
|
|
} elsif (ref $vref eq 'ARRAY') { |
64 |
|
|
foreach (@{$vref}) { |
65 |
|
|
if (ref $_ ne 'SCALAR') { |
66 |
|
|
var_utf2iso($_); |
67 |
|
|
} else { |
68 |
|
|
$_ = scalar2iso($_); |
69 |
|
|
} |
70 |
|
|
} |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
sub scalar2iso { |
76 |
|
|
my $scalar = shift; |
77 |
|
|
if ($scalar) { |
78 |
|
|
my $u = utf8($scalar); |
79 |
|
|
return $u->latin1; |
80 |
|
|
} |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
1; |