--- nfo/perl/libs/Data/Mungle/Transform/Deep.pm 2003/02/20 20:48:00 1.10 +++ nfo/perl/libs/Data/Mungle/Transform/Deep.pm 2003/02/21 01:48:50 1.13 @@ -1,7 +1,16 @@ ## --------------------------------------------------------------------------- -## $Id: Deep.pm,v 1.10 2003/02/20 20:48:00 joko Exp $ +## $Id: Deep.pm,v 1.13 2003/02/21 01:48:50 joko Exp $ ## --------------------------------------------------------------------------- ## $Log: Deep.pm,v $ +## Revision 1.13 2003/02/21 01:48:50 joko +## renamed core function +## +## Revision 1.12 2003/02/20 22:45:19 joko +## fix regarding new deep_copy +## +## Revision 1.11 2003/02/20 21:13:54 joko +## - removed implementation of deep_copy2 - get this from the Pitonyak namespace (now cloned to repository) +## ## Revision 1.10 2003/02/20 20:48:00 joko ## - refactored lots of code to Data::Code::Ref ## + alternative 'deep_copy' implementation @@ -58,6 +67,7 @@ use Data::Dumper; use Iterate; +use Pitonyak::DeepCopy; use Data::Transform::Encode qw( latin_to_utf8 latin_to_utf8_scalar utf8_to_latin utf8_to_latin_scalar ); use Data::Code::Ref qw( ref_slot ); @@ -129,6 +139,8 @@ } +# convert values in hash to utf8 (and back) to be ready for (e.g.) encapsulation in XML +# but still using the known latin locale stuff sub expand { my $obj = shift; @@ -198,7 +210,7 @@ # convert all values to utf8 (inside complex struct) # now done in core-item-callbacks via Greg London's "Iterate" from CPAN - # var2utf8($result) if ($options->{utf8}); + # latin_to_utf8($result) if ($options->{utf8}); # destroy persistent object from memory to be sure to get a fresh one next time #undef $obj if $options->{destroy}; @@ -441,58 +453,10 @@ # ACK's go to Andrew Pitonyak # Copyright 2002, Andrew Pitonyak (perlboy@pitonyak.org) # please visit: http://www.pitonyak.org/code/perl/Pitonyak/DeepCopy.pm.html -sub deep_copy2 { - - # if not defined then return it - return undef if $#_ < 0 || !defined( $_[0] ); - - # if not a reference then return the parameter - return $_[0] if !ref( $_[0] ); - my $obj = shift; - if ( UNIVERSAL::isa( $obj, 'SCALAR' ) ) { - my $temp = deep_copy2($$obj); - return \$temp; - } - elsif ( UNIVERSAL::isa( $obj, 'HASH' ) ) { - my $temp_hash = {}; - foreach my $key ( keys %$obj ) { - if ( !defined( $obj->{$key} ) || !ref( $obj->{$key} ) ) { - $temp_hash->{$key} = $obj->{$key}; - } - else { - $temp_hash->{$key} = deep_copy2( $obj->{$key} ); - } - } - return $temp_hash; - } - elsif ( UNIVERSAL::isa( $obj, 'ARRAY' ) ) { - my $temp_array = []; - foreach my $array_val (@$obj) { - if ( !defined($array_val) || !ref($array_val) ) { - push ( @$temp_array, $array_val ); - } - else { - push ( @$temp_array, deep_copy2($array_val) ); - } - } - return $temp_array; - } - - # ?? I am uncertain about this one - elsif ( UNIVERSAL::isa( $obj, 'REF' ) ) { - my $temp = deep_copy2($$obj); - return \$temp; - } - - # I guess that it is either CODE, GLOB or LVALUE - else { - return $obj; - } -} - sub deep_copy { - deep_copy2(@_); + Pitonyak::DeepCopy::deep_copy(@_); } + 1; __END__