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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Thu Mar 27 15:17:07 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.3: +5 -2 lines
namespace fixes for Data::Mungle::*

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

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