2 |
## $Id$ |
## $Id$ |
3 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.13 2003/02/21 01:48:50 joko |
6 |
|
## renamed core function |
7 |
|
## |
8 |
|
## Revision 1.12 2003/02/20 22:45:19 joko |
9 |
|
## fix regarding new deep_copy |
10 |
|
## |
11 |
|
## Revision 1.11 2003/02/20 21:13:54 joko |
12 |
|
## - removed implementation of deep_copy2 - get this from the Pitonyak namespace (now cloned to repository) |
13 |
|
## |
14 |
## Revision 1.10 2003/02/20 20:48:00 joko |
## Revision 1.10 2003/02/20 20:48:00 joko |
15 |
## - refactored lots of code to Data::Code::Ref |
## - refactored lots of code to Data::Code::Ref |
16 |
## + alternative 'deep_copy' implementation |
## + alternative 'deep_copy' implementation |
67 |
use Data::Dumper; |
use Data::Dumper; |
68 |
use Iterate; |
use Iterate; |
69 |
|
|
70 |
|
use Pitonyak::DeepCopy; |
71 |
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 ); |
72 |
use Data::Code::Ref qw( ref_slot ); |
use Data::Code::Ref qw( ref_slot ); |
73 |
|
|
139 |
} |
} |
140 |
|
|
141 |
|
|
142 |
|
# convert values in hash to utf8 (and back) to be ready for (e.g.) encapsulation in XML |
143 |
|
# but still using the known latin locale stuff |
144 |
sub expand { |
sub expand { |
145 |
|
|
146 |
my $obj = shift; |
my $obj = shift; |
210 |
|
|
211 |
# convert all values to utf8 (inside complex struct) |
# convert all values to utf8 (inside complex struct) |
212 |
# 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 |
213 |
# var2utf8($result) if ($options->{utf8}); |
# latin_to_utf8($result) if ($options->{utf8}); |
214 |
|
|
215 |
# 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 |
216 |
#undef $obj if $options->{destroy}; |
#undef $obj if $options->{destroy}; |
453 |
# ACK's go to Andrew Pitonyak |
# ACK's go to Andrew Pitonyak |
454 |
# Copyright 2002, Andrew Pitonyak (perlboy@pitonyak.org) |
# Copyright 2002, Andrew Pitonyak (perlboy@pitonyak.org) |
455 |
# please visit: http://www.pitonyak.org/code/perl/Pitonyak/DeepCopy.pm.html |
# 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; |
|
|
} |
|
|
} |
|
|
|
|
456 |
sub deep_copy { |
sub deep_copy { |
457 |
deep_copy2(@_); |
Pitonyak::DeepCopy::deep_copy(@_); |
458 |
} |
} |
459 |
|
|
460 |
|
|
461 |
1; |
1; |
462 |
__END__ |
__END__ |