/[cvs]/nfo/perl/libs/Data/Mungle/Transform/Encode.pm
ViewVC logotype

Annotation of /nfo/perl/libs/Data/Mungle/Transform/Encode.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Thu Dec 5 13:57:22 2002 UTC (21 years, 7 months ago) by joko
Branch: MAIN
Changes since 1.1: +8 -3 lines
+ now able to export 'scalar2utf8'
+ comments

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed