Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Data::Dumper and tied objects

0 views
Skip to first unread message

Slaven Rezic

unread,
Sep 9, 2002, 1:55:43 PM9/9/02
to perl5-...@perl.org
I do not see support for tied objects in Data::Dumper. A dump of a
tied object would result in a normal hash, arrays or scalar _without_
any information to restore the tied object. Do I miss something or is
this really lacking? I would be happy to look into Data::Dumper and
add support for this.

Regards,
Slaven

--
Slaven Rezic - slaven...@berlin.de

tkrevdiff - graphical display of diffs between revisions (RCS or CVS)
http://ptktools.sourceforge.net/#tkrevdiff

Brian Ingerson

unread,
Sep 9, 2002, 2:11:31 PM9/9/02
to Slaven Rezic, perl5-...@perl.org
On 09/09/02 19:55 +0200, Slaven Rezic wrote:
> I do not see support for tied objects in Data::Dumper. A dump of a
> tied object would result in a normal hash, arrays or scalar _without_
> any information to restore the tied object. Do I miss something or is
> this really lacking? I would be happy to look into Data::Dumper and
> add support for this.

My personal opinion on this is that 'tie' is for doing things that lay
outside of serialization. 'tie' is for when you are trying add semantics to a
hash, but still have it look like a normal hash. Serialization blows it's
cover so to speak.

YAML.pm can serialize more native data structures than any other dumper.
Everything from globs to coderefs to opaque objects to file-handles. But I
leave tied stuff alone. The creator of the tied thingy wanted me to think it
was just a thingy, and I respect that.

Cheers, Brian

Slaven Rezic

unread,
Sep 9, 2002, 3:48:06 PM9/9/02
to Brian Ingerson, perl5-...@perl.org
Brian Ingerson <in...@ttul.org> writes:

My actual problem is that I have nested objects with ordered hashes
(using Tie::IxHash). Data::Dumper destroys the order by storing the
Tie::IxHash objects as normal hashes.

It would be nice to have an option (not the default) for Data::Dumper
to serialize the internal representation of a tied object.

Regards,
Slaven

--
Slaven Rezic - slaven...@berlin.de

tktimex - project time manager
http://sourceforge.net/projects/ptktools/

Benjamin Goldberg

unread,
Sep 10, 2002, 12:52:55 AM9/10/02
to slaven...@berlin.de, perl5-...@perl.org
Slaven Rezic wrote:
>
> I do not see support for tied objects in Data::Dumper. A dump of a
> tied object would result in a normal hash, arrays or scalar _without_
> any information to restore the tied object. Do I miss something or is
> this really lacking? I would be happy to look into Data::Dumper and
> add support for this.

To safely serialize a tied thing, you would first need to
(1) fetch the object it's tied to using tied()
(2) temporarily bless that object into another class
(to avoid having it's "UNTIE" method being called)
(3) untie the thing
(4) bless the object into it's original class
(5) serialize both the now untied thing,
and the object it was tied to
(6) restore the tie, using Tie::Restore or somesuch.

--
tr/`4/ /d, print "@{[map --$| ? ucfirst lc : lc, split]},\n" for
pack 'u', pack 'H*', 'ab5cf4021bafd28972030972b00a218eb9720000';

0 new messages