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

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

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