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

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

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

revision 1.11 by joko, Thu Feb 20 21:13:54 2003 UTC revision 1.16 by joko, Thu Mar 27 15:04:52 2003 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ---------------------------------------------------------------------------  ## ---------------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.16  2003/03/27 15:04:52  joko
6    ##  minor update: comment
7    ##
8    ##  Revision 1.15  2003/02/27 14:39:48  jonen
9    ##  + fixed bug at _hash2object()
10    ##
11    ##  Revision 1.14  2003/02/22 17:13:55  jonen
12    ##  + added function 'childObject2string()' to encode 'child'-references to option related string
13    ##  + use new option at 'expand()' for replacing 'childObject2string'
14    ##
15    ##  Revision 1.13  2003/02/21 01:48:50  joko
16    ##  renamed core function
17    ##
18    ##  Revision 1.12  2003/02/20 22:45:19  joko
19    ##  fix regarding new deep_copy
20    ##
21  ##  Revision 1.11  2003/02/20 21:13:54  joko  ##  Revision 1.11  2003/02/20 21:13:54  joko
22  ##  - removed implementation of deep_copy2 - get this from the Pitonyak namespace (now cloned to repository)  ##  - removed implementation of deep_copy2 - get this from the Pitonyak namespace (now cloned to repository)
23  ##  ##
# Line 61  use attributes; Line 77  use attributes;
77  use Data::Dumper;  use Data::Dumper;
78  use Iterate;  use Iterate;
79    
80    use Pitonyak::DeepCopy;
81  use Data::Transform::Encode qw( latin_to_utf8 latin_to_utf8_scalar utf8_to_latin utf8_to_latin_scalar );  use Data::Transform::Encode qw( latin_to_utf8 latin_to_utf8_scalar utf8_to_latin utf8_to_latin_scalar );
82  use Data::Code::Ref qw( ref_slot );  use Data::Code::Ref qw( ref_slot );
83    
# Line 132  sub _var_deref_test { Line 149  sub _var_deref_test {
149  }  }
150    
151    
152    # convert values in hash to utf8 (and back) to be ready for (e.g.) encapsulation in XML
153    # but still using the known latin locale stuff
154  sub expand {  sub expand {
155    
156    my $obj = shift;    my $obj = shift;
# Line 146  sub expand { Line 165  sub expand {
165        my $item;        my $item;
166        # if current item is a reference ...        # if current item is a reference ...
167        if (ref $_[0]) {        if (ref $_[0]) {
168          # ... expand structure recursively          $item = $_[0];
169          $item = expand($_[0], $options);          # if $options->{childObj2string} is TRUE or STRING don't expand referenced object,
170            # instead replace it by per option choosed string (default: o_<classname>_<ref type>_<guid> )
171            if ($item && $options->{childObj2string}) {
172              $item = childObj2string($item, $options->{childObj2string});
173            } else {
174              # ... expand structure recursively
175              $item = expand($_[0], $options);
176            }
177          # destroy item via seperate callback method (a POST) if requested          # destroy item via seperate callback method (a POST) if requested
178          #$options->{cb}->{destroy}->($_[0]) if $options->{destroy};          #$options->{cb}->{destroy}->($_[0]) if $options->{destroy};
179    
# Line 176  sub expand { Line 202  sub expand {
202                
203        # if current item is a reference ...        # if current item is a reference ...
204        if (ref $_[1]) {        if (ref $_[1]) {
205          # ... expand structure recursively          $item = $_[1];
206          $item = expand($_[1], $options);          # if $options->{childObj2string} is TRUE or STRING don't expand referenced object,
207            # instead replace it by per option choosed string (default: o_<classname>_<ref type>_<guid> )
208            if ($item && $options->{childObj2string} && !(ref $_[1] eq "ARRAY") && !(ref $_[1] eq "HASH")) {
209              $item = childObj2string($item, $options->{childObj2string});
210            } else {
211              # ... expand structure recursively
212              $item = expand($_[1], $options);
213            }
214          # destroy item via seperate callback method (a POST) if requested          # destroy item via seperate callback method (a POST) if requested
215          #$options->{cb}->{destroy}->($_[1]) if $options->{destroy};          #$options->{cb}->{destroy}->($_[1]) if $options->{destroy};
216                
# Line 201  sub expand { Line 234  sub expand {
234    
235    # convert all values to utf8 (inside complex struct)    # convert all values to utf8 (inside complex struct)
236      # now done in core-item-callbacks via Greg London's "Iterate" from CPAN      # now done in core-item-callbacks via Greg London's "Iterate" from CPAN
237      # var2utf8($result) if ($options->{utf8});      # latin_to_utf8($result) if ($options->{utf8});
238    
239    # destroy persistent object from memory to be sure to get a fresh one next time    # destroy persistent object from memory to be sure to get a fresh one next time
240    #undef $obj if $options->{destroy};    #undef $obj if $options->{destroy};
# Line 261  sub _var_traverse_mixin_update_old { Line 294  sub _var_traverse_mixin_update_old {
294  sub merge_to {  sub merge_to {
295    _hash2object(@_);    _hash2object(@_);
296    # TODO:    # TODO:
297    # re-implement using CPAN's "Iterate".    # re-implement using CPAN's "Iterate" and/or a modified Hash::Merge.
298  }  }
299    
300    
# Line 278  sub _hash2object { Line 311  sub _hash2object {
311    numhash2list($data) if ($options->{php});    numhash2list($data) if ($options->{php});
312    
313    # utf8-conversion/-encoding (essential for I18N)    # utf8-conversion/-encoding (essential for I18N)
314    var_utf2iso($data) if ($options->{utf8});    utf8_to_latin($data) if ($options->{utf8});
315    
316    # get fresh object from database    # get fresh object from database
317    # todo:    # todo:
# Line 445  sub deep_copy1 { Line 478  sub deep_copy1 {
478  # Copyright 2002, Andrew Pitonyak (perlboy@pitonyak.org)  # Copyright 2002, Andrew Pitonyak (perlboy@pitonyak.org)
479  # please visit: http://www.pitonyak.org/code/perl/Pitonyak/DeepCopy.pm.html  # please visit: http://www.pitonyak.org/code/perl/Pitonyak/DeepCopy.pm.html
480  sub deep_copy {  sub deep_copy {
481    Pitonyak::deep_copy(@_);    Pitonyak::DeepCopy::deep_copy(@_);
482  }  }
483    
484    
485    sub childObj2string {
486      my $obj = shift;
487      my $option = shift;
488      my $classname = ref $obj;
489      
490      if($option == 1) {
491        my $string = "o_" . $classname . "_" .$obj->{guid};
492        return $string;
493      }  
494    }
495    
496    
497  1;  1;
498  __END__  __END__

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.16

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