| 1 |
############################################## |
## --------------------------------------------------------------------------- |
| 2 |
# |
## $Id$ |
| 3 |
# $Id$ |
## --------------------------------------------------------------------------- |
| 4 |
# |
## $Log$ |
| 5 |
# $Log$ |
## Revision 1.7 2003/01/19 03:26:59 joko |
| 6 |
# Revision 1.6 2002/12/23 11:27:53 jonen |
## + added 'sub deep_copy' - refactored from libp |
| 7 |
# + changed behavior WATCH! |
## + add 'sub merge' - exported from CPAN's 'Hash::Merge' |
| 8 |
# |
## |
| 9 |
# Revision 1.5 2002/12/16 19:57:54 joko |
## Revision 1.6 2002/12/23 11:27:53 jonen |
| 10 |
# + option 'init' |
## + changed behavior WATCH! |
| 11 |
# |
## |
| 12 |
# Revision 1.4 2002/12/05 13:56:49 joko |
## Revision 1.5 2002/12/16 19:57:54 joko |
| 13 |
# - var_deref |
## + option 'init' |
| 14 |
# + expand - more sophisticated dereferencing with callbacks using Iterate |
## |
| 15 |
# |
## Revision 1.4 2002/12/05 13:56:49 joko |
| 16 |
# Revision 1.3 2002/12/03 05:34:55 joko |
## - var_deref |
| 17 |
# + bugfix: now utilizing var_utf2iso from Data::Transform::Encode |
## + expand - more sophisticated dereferencing with callbacks using Iterate |
| 18 |
# |
## |
| 19 |
# Revision 1.2 2002/12/01 04:44:07 joko |
## Revision 1.3 2002/12/03 05:34:55 joko |
| 20 |
# + code from Data::Transform::OO |
## + bugfix: now utilizing var_utf2iso from Data::Transform::Encode |
| 21 |
# |
## |
| 22 |
# Revision 1.1 2002/11/29 04:49:20 joko |
## Revision 1.2 2002/12/01 04:44:07 joko |
| 23 |
# + initial check-in |
## + code from Data::Transform::OO |
| 24 |
# |
## |
| 25 |
# Revision 1.1 2002/10/10 03:26:00 cvsjoko |
## Revision 1.1 2002/11/29 04:49:20 joko |
| 26 |
# + new |
## + initial check-in |
| 27 |
# |
## |
| 28 |
############################################## |
## Revision 1.1 2002/10/10 03:26:00 cvsjoko |
| 29 |
|
## + new |
| 30 |
|
## --------------------------------------------------------------------------- |
| 31 |
|
|
| 32 |
|
|
| 33 |
package Data::Transform::Deep; |
package Data::Transform::Deep; |
| 44 |
&hash2object |
&hash2object |
| 45 |
&refexpr2perlref |
&refexpr2perlref |
| 46 |
&expand |
&expand |
| 47 |
|
&deep_copy |
| 48 |
|
&merge |
| 49 |
); |
); |
| 50 |
# &var_deref |
# &var_deref |
| 51 |
# &getStructSlotByStringyAddress |
# &getStructSlotByStringyAddress |
| 53 |
use attributes; |
use attributes; |
| 54 |
use Data::Dumper; |
use Data::Dumper; |
| 55 |
use Data::Transform::Encode qw( var_utf2iso var2utf8 scalar2utf8 ); |
use Data::Transform::Encode qw( var_utf2iso var2utf8 scalar2utf8 ); |
| 56 |
use libp qw( deep_copy ); |
|
| 57 |
|
use Hash::Merge qw( merge ); |
| 58 |
|
#use libp qw( deep_copy ); |
| 59 |
use Iterate; |
use Iterate; |
| 60 |
|
|
| 61 |
sub var_NumericalHashToArray { |
sub var_NumericalHashToArray { |
| 322 |
# @fields = keys %{$data} if $options->{mixin}; |
# @fields = keys %{$data} if $options->{mixin}; |
| 323 |
|
|
| 324 |
foreach (@fields) { |
foreach (@fields) { |
| 325 |
push @indexstack, $_; |
my $field = $_; |
| 326 |
|
push @indexstack, $field; |
| 327 |
|
|
| 328 |
# determine type of object |
# determine type of object |
| 329 |
my $ref = ref $object->{$_}; |
my $ref = ref $object->{$field}; |
| 330 |
# print STDERR "attrname: $_ ATTRref: $ref", "\n"; |
# print STDERR "attrname: $_ ATTRref: $ref", "\n"; |
| 331 |
if ($ref) { |
if ($ref) { |
| 332 |
hash2object_traverse_mixin($object->{$_}, $data, 1, $options); |
hash2object_traverse_mixin($object->{$field}, $data, 1, $options); |
| 333 |
} else { |
} else { |
| 334 |
my $val = getStructSlotByStringyAddress($data, \@indexstack); |
my $val = getStructSlotByStringyAddress($data, \@indexstack); |
| 335 |
$object->{$_} = $val if defined $val; |
|
| 336 |
|
print Dumper($options); |
| 337 |
|
my $field_target = $field; |
| 338 |
|
if (my $pattern = $options->{pattern_strip_key}) { |
| 339 |
|
print "pattern: $pattern", "\n"; |
| 340 |
|
$field_target =~ s/$pattern//; |
| 341 |
|
print "field: $field_target", "\n"; |
| 342 |
|
} |
| 343 |
|
|
| 344 |
|
$object->{$field_target} = $val if defined $val; |
| 345 |
} |
} |
| 346 |
pop @indexstack; |
pop @indexstack; |
| 347 |
} |
} |
| 471 |
return (join('->', @parts_capsule), \@parts_pure); |
return (join('->', @parts_capsule), \@parts_pure); |
| 472 |
} |
} |
| 473 |
|
|
| 474 |
|
# ACK's go to ... |
| 475 |
|
sub deep_copy { |
| 476 |
|
my $this = shift; |
| 477 |
|
if (not ref $this) { |
| 478 |
|
$this; |
| 479 |
|
} elsif (ref $this eq "ARRAY") { |
| 480 |
|
[map deep_copy($_), @$this]; |
| 481 |
|
} elsif (ref $this eq "HASH") { |
| 482 |
|
+{map { $_ => deep_copy($this->{$_}) } keys %$this}; |
| 483 |
|
} elsif (ref $this eq "CODE") { |
| 484 |
|
$this; |
| 485 |
|
#} else { die "deep_copy asks: what type is $this?" } |
| 486 |
|
} else { print "deep_copy asks: what type is $this?", "\n"; } |
| 487 |
|
} |
| 488 |
|
|
| 489 |
1; |
1; |