2 |
## $Id$ |
## $Id$ |
3 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.22 2003/05/10 17:09:18 jonen |
6 |
|
## + added keep of empty arrays/hashes if 'expand' for php |
7 |
|
## |
8 |
|
## Revision 1.21 2003/04/09 07:21:56 joko |
9 |
|
## childObj2string now inside Encode.pm, renamed to 'twingle_reference' |
10 |
|
## |
11 |
|
## Revision 1.20 2003/04/04 17:31:23 joko |
12 |
|
## minor update to 'childObj2string' |
13 |
|
## |
14 |
|
## Revision 1.19 2003/03/28 03:11:25 jonen |
15 |
|
## + bugfix |
16 |
|
## |
17 |
|
## Revision 1.18 2003/03/28 03:07:26 jonen |
18 |
|
## + minor changes |
19 |
|
## |
20 |
|
## Revision 1.17 2003/03/27 15:17:07 joko |
21 |
|
## namespace fixes for Data::Mungle::* |
22 |
|
## |
23 |
|
## Revision 1.16 2003/03/27 15:04:52 joko |
24 |
|
## minor update: comment |
25 |
|
## |
26 |
## Revision 1.15 2003/02/27 14:39:48 jonen |
## Revision 1.15 2003/02/27 14:39:48 jonen |
27 |
## + fixed bug at _hash2object() |
## + fixed bug at _hash2object() |
28 |
## |
## |
77 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
78 |
|
|
79 |
|
|
80 |
package Data::Transform::Deep; |
package Data::Mungle::Transform::Deep; |
81 |
|
|
82 |
use strict; |
use strict; |
83 |
use warnings; |
use warnings; |
96 |
use Iterate; |
use Iterate; |
97 |
|
|
98 |
use Pitonyak::DeepCopy; |
use Pitonyak::DeepCopy; |
99 |
use Data::Transform::Encode qw( latin_to_utf8 latin_to_utf8_scalar utf8_to_latin utf8_to_latin_scalar ); |
use Data::Mungle::Transform::Encode qw( latin_to_utf8 latin_to_utf8_scalar utf8_to_latin utf8_to_latin_scalar twingle_reference ); |
100 |
use Data::Code::Ref qw( ref_slot ); |
use Data::Mungle::Code::Ref qw( ref_slot ); |
101 |
|
|
102 |
sub numhash2list { |
sub numhash2list { |
103 |
my $vref = shift; |
my $vref = shift; |
178 |
#print "ref: ", ref $obj, "\n"; |
#print "ref: ", ref $obj, "\n"; |
179 |
|
|
180 |
if (ref $obj eq 'ARRAY') { |
if (ref $obj eq 'ARRAY') { |
181 |
|
|
182 |
|
# if we expand for php, keep empty ARRAY |
183 |
|
if($#$obj == -1 && $options->{childObj2string}) { |
184 |
|
$result = $obj; |
185 |
|
} else { |
186 |
IterArray @$obj, sub { |
IterArray @$obj, sub { |
187 |
my $item; |
my $item; |
188 |
# if current item is a reference ... |
# if current item is a reference ... |
191 |
# if $options->{childObj2string} is TRUE or STRING don't expand referenced object, |
# if $options->{childObj2string} is TRUE or STRING don't expand referenced object, |
192 |
# instead replace it by per option choosed string (default: o_<classname>_<ref type>_<guid> ) |
# instead replace it by per option choosed string (default: o_<classname>_<ref type>_<guid> ) |
193 |
if ($item && $options->{childObj2string}) { |
if ($item && $options->{childObj2string}) { |
194 |
$item = childObj2string($item, $options->{childObj2string}); |
$item = twingle_reference($item); |
195 |
} else { |
} else { |
196 |
# ... expand structure recursively |
# ... expand structure recursively |
197 |
$item = expand($_[0], $options); |
$item = expand($_[0], $options); |
211 |
push(@{$result}, $item); # use item in any case |
push(@{$result}, $item); # use item in any case |
212 |
|
|
213 |
} |
} |
214 |
|
} |
215 |
|
|
216 |
} elsif (ref $obj eq 'CODE') { |
} elsif (ref $obj eq 'CODE') { |
217 |
#print Dumper($obj); |
#print Dumper($obj); |
219 |
|
|
220 |
# TODO: "} elsif (ref $obj eq 'HASH') { [...] } else { croak 'could not deref blah'; }" ??? |
# TODO: "} elsif (ref $obj eq 'HASH') { [...] } else { croak 'could not deref blah'; }" ??? |
221 |
} elsif (ref $obj) { |
} elsif (ref $obj) { |
222 |
|
|
223 |
|
# if we expand for php, keep empty HASH |
224 |
|
my @tmp = keys %$obj; |
225 |
|
if($#tmp == -1 && $options->{childObj2string}) { |
226 |
|
$result = $obj; |
227 |
|
} else { |
228 |
IterHash %$obj, sub { |
IterHash %$obj, sub { |
229 |
my $item; |
my $item; |
230 |
|
|
233 |
$item = $_[1]; |
$item = $_[1]; |
234 |
# if $options->{childObj2string} is TRUE or STRING don't expand referenced object, |
# if $options->{childObj2string} is TRUE or STRING don't expand referenced object, |
235 |
# instead replace it by per option choosed string (default: o_<classname>_<ref type>_<guid> ) |
# instead replace it by per option choosed string (default: o_<classname>_<ref type>_<guid> ) |
236 |
if ($item && $options->{childObj2string} && !(ref $_[1] eq "ARRAY") && !(ref $_[1] eq "HASH")) { |
if ($item && $options->{childObj2string} && !(ref $_[1] eq "ARRAY") && !(ref $_[1] eq "HASH") && !(ref $_[1] eq "Set::Object")) { |
237 |
$item = childObj2string($item, $options->{childObj2string}); |
$item = twingle_reference($item); |
238 |
} else { |
} else { |
239 |
# ... expand structure recursively |
# ... expand structure recursively |
240 |
$item = expand($_[1], $options); |
$item = expand($_[1], $options); |
253 |
#$result->{$_[0]} = $item if $item; # use item only if not undef (TODO: make configurable via $options) |
#$result->{$_[0]} = $item if $item; # use item only if not undef (TODO: make configurable via $options) |
254 |
$result->{$_[0]} = $item; # use item in any case |
$result->{$_[0]} = $item; # use item in any case |
255 |
} |
} |
256 |
|
} |
257 |
|
|
258 |
} else { |
} else { |
259 |
#die ("not a reference!"); |
#die ("not a reference!"); |
323 |
sub merge_to { |
sub merge_to { |
324 |
_hash2object(@_); |
_hash2object(@_); |
325 |
# TODO: |
# TODO: |
326 |
# re-implement using CPAN's "Iterate". |
# re-implement using CPAN's "Iterate" and/or a modified Hash::Merge. |
327 |
} |
} |
328 |
|
|
329 |
|
|
511 |
} |
} |
512 |
|
|
513 |
|
|
|
sub childObj2string { |
|
|
my $obj = shift; |
|
|
my $option = shift; |
|
|
my $classname = ref $obj; |
|
|
|
|
|
if($option == 1) { |
|
|
my $string = "o_" . $classname . "_" .$obj->{guid}; |
|
|
return $string; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
514 |
1; |
1; |
515 |
__END__ |
__END__ |