in reply to Creating a Moose object and serializing it

It intuitively seems to me that “a Moose object” is too much to be serializing.   What you really want to serialize, I would think, is a portion of the data associated with the object.   Undoubtedly there is a Moose appendage designed to do just that:   find it and use it.

If you try to serialize “an object,” (i.e. “functional pieces and all”), you might wind up with a stored object that you one day cannot restore, because the underlying implementation somewhere in Moose (or in something you have built) has changed. When you try to restore the whole thing, what is resurrected, right before your eyes, is a ghost from the past ... no longer compatible with the present.

Conceptually, I would think you would want (a fairly base-class) to provide methods such as, say, freeze_into(streamname) and thaw_from.   You instantiate the object, then you tell it to thaw-from some persistent data store.   Later, before destroying the object or allowing it to perish, you tell it to freeze-into.   In this way, the object is clearly differentiated from the state-data.   (And, you have a clearly-defined error path that you can take if you discover that the saved data is no longer compatible with the object.)   For most of the application, this would be something that “Just Works.™” ... a bit of magick that every object knows how to do.

Replies are listed 'Best First'.
Re^2: Creating a Moose object and serializing it
by stvn (Monsignor) on Oct 25, 2010 at 16:08 UTC
    It intuitively seems to me that “a Moose object” is too much to be serializing.

    Actually, your intuition is wrong, a "Moose object" is just regular old HASH reference, just like any other plain old Perl object you might create. There is no magic involved there, in fact it is pretty boring.

    The only time Moose will add anything else to an instance, is if you start doing fancy stuff like applying roles to an instance, in which case it needs to keep a local reference to the metaclass and that can get ugly.

    -stvn