2 |
## $Id$ |
## $Id$ |
3 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.15 2003/02/27 14:39:48 jonen |
6 |
|
## + fixed bug at _hash2object() |
7 |
|
## |
8 |
|
## Revision 1.14 2003/02/22 17:13:55 jonen |
9 |
|
## + added function 'childObject2string()' to encode 'child'-references to option related string |
10 |
|
## + use new option at 'expand()' for replacing 'childObject2string' |
11 |
|
## |
12 |
|
## Revision 1.13 2003/02/21 01:48:50 joko |
13 |
|
## renamed core function |
14 |
|
## |
15 |
|
## Revision 1.12 2003/02/20 22:45:19 joko |
16 |
|
## fix regarding new deep_copy |
17 |
|
## |
18 |
## Revision 1.11 2003/02/20 21:13:54 joko |
## Revision 1.11 2003/02/20 21:13:54 joko |
19 |
## - 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) |
20 |
## |
## |
74 |
use Data::Dumper; |
use Data::Dumper; |
75 |
use Iterate; |
use Iterate; |
76 |
|
|
77 |
|
use Pitonyak::DeepCopy; |
78 |
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 ); |
79 |
use Data::Code::Ref qw( ref_slot ); |
use Data::Code::Ref qw( ref_slot ); |
80 |
|
|
146 |
} |
} |
147 |
|
|
148 |
|
|
149 |
|
# convert values in hash to utf8 (and back) to be ready for (e.g.) encapsulation in XML |
150 |
|
# but still using the known latin locale stuff |
151 |
sub expand { |
sub expand { |
152 |
|
|
153 |
my $obj = shift; |
my $obj = shift; |
162 |
my $item; |
my $item; |
163 |
# if current item is a reference ... |
# if current item is a reference ... |
164 |
if (ref $_[0]) { |
if (ref $_[0]) { |
165 |
# ... expand structure recursively |
$item = $_[0]; |
166 |
$item = expand($_[0], $options); |
# if $options->{childObj2string} is TRUE or STRING don't expand referenced object, |
167 |
|
# instead replace it by per option choosed string (default: o_<classname>_<ref type>_<guid> ) |
168 |
|
if ($item && $options->{childObj2string}) { |
169 |
|
$item = childObj2string($item, $options->{childObj2string}); |
170 |
|
} else { |
171 |
|
# ... expand structure recursively |
172 |
|
$item = expand($_[0], $options); |
173 |
|
} |
174 |
# destroy item via seperate callback method (a POST) if requested |
# destroy item via seperate callback method (a POST) if requested |
175 |
#$options->{cb}->{destroy}->($_[0]) if $options->{destroy}; |
#$options->{cb}->{destroy}->($_[0]) if $options->{destroy}; |
176 |
|
|
199 |
|
|
200 |
# if current item is a reference ... |
# if current item is a reference ... |
201 |
if (ref $_[1]) { |
if (ref $_[1]) { |
202 |
# ... expand structure recursively |
$item = $_[1]; |
203 |
$item = expand($_[1], $options); |
# if $options->{childObj2string} is TRUE or STRING don't expand referenced object, |
204 |
|
# instead replace it by per option choosed string (default: o_<classname>_<ref type>_<guid> ) |
205 |
|
if ($item && $options->{childObj2string} && !(ref $_[1] eq "ARRAY") && !(ref $_[1] eq "HASH")) { |
206 |
|
$item = childObj2string($item, $options->{childObj2string}); |
207 |
|
} else { |
208 |
|
# ... expand structure recursively |
209 |
|
$item = expand($_[1], $options); |
210 |
|
} |
211 |
# destroy item via seperate callback method (a POST) if requested |
# destroy item via seperate callback method (a POST) if requested |
212 |
#$options->{cb}->{destroy}->($_[1]) if $options->{destroy}; |
#$options->{cb}->{destroy}->($_[1]) if $options->{destroy}; |
213 |
|
|
231 |
|
|
232 |
# convert all values to utf8 (inside complex struct) |
# convert all values to utf8 (inside complex struct) |
233 |
# 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 |
234 |
# var2utf8($result) if ($options->{utf8}); |
# latin_to_utf8($result) if ($options->{utf8}); |
235 |
|
|
236 |
# 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 |
237 |
#undef $obj if $options->{destroy}; |
#undef $obj if $options->{destroy}; |
308 |
numhash2list($data) if ($options->{php}); |
numhash2list($data) if ($options->{php}); |
309 |
|
|
310 |
# utf8-conversion/-encoding (essential for I18N) |
# utf8-conversion/-encoding (essential for I18N) |
311 |
var_utf2iso($data) if ($options->{utf8}); |
utf8_to_latin($data) if ($options->{utf8}); |
312 |
|
|
313 |
# get fresh object from database |
# get fresh object from database |
314 |
# todo: |
# todo: |
475 |
# Copyright 2002, Andrew Pitonyak (perlboy@pitonyak.org) |
# Copyright 2002, Andrew Pitonyak (perlboy@pitonyak.org) |
476 |
# please visit: http://www.pitonyak.org/code/perl/Pitonyak/DeepCopy.pm.html |
# please visit: http://www.pitonyak.org/code/perl/Pitonyak/DeepCopy.pm.html |
477 |
sub deep_copy { |
sub deep_copy { |
478 |
Pitonyak::deep_copy(@_); |
Pitonyak::DeepCopy::deep_copy(@_); |
479 |
} |
} |
480 |
|
|
481 |
|
|
482 |
|
sub childObj2string { |
483 |
|
my $obj = shift; |
484 |
|
my $option = shift; |
485 |
|
my $classname = ref $obj; |
486 |
|
|
487 |
|
if($option == 1) { |
488 |
|
my $string = "o_" . $classname . "_" .$obj->{guid}; |
489 |
|
return $string; |
490 |
|
} |
491 |
|
} |
492 |
|
|
493 |
|
|
494 |
1; |
1; |
495 |
__END__ |
__END__ |