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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.4

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