Is there a reason why I should NOT serialize objects (Moose) using Storable or YAML?

I have several Moose objects and some other simple hash objects (hashes, arrays) that I would like to serialize.

At first I used a simple

my $obj_store_file = nstore($obj); 

and

 my $obj = retrieve($obj_store_file); 

It worked out well.

Later I found near MooseX::Storage and KiokuDB . I tried to use them to take advantage of some of the benefits they have, but:

  • MooseX::Storage seemed to recreate objects that are transferred multiple times. For example, one of my serialized objects contains several attributes, each of which refers to one instance of another object. Before serialization, all of these links are obviously the same - they all point to the same object. After serialization / deserialization using MooseX::Storage this one object is duplicated once, and each link points to a different instance of the object. I was told that MooseX::Storage not suitable for representing graphs of objects and that I can try KiokuDB .
  • I did, although I felt that KiokuDB is redundant for my needs. I don’t need all the fancy stuff the DB can offer. Unfortunately, since one of my objects is really large and changes memory during a sequential conversion using the default values, it seems to me that I should write my own serializer or save its β€œdata” separately, and then write a suit of KiokuX::Module ... again, pretty overkill.

So, I will return to ordinary or YAML. My question is simple: yes, there are some advantages to KiokuDB (especially the fact that it supports an object graph) and, possibly, also to MooseX::Storage (although I could not find them for the latter). But, considering that these advantages are not very useful for me, is there any reason not to use Storable or YAML?

In other words, is there something wrong with saving the object (Moose) this way? It's illegal?

+4
source share
1 answer

My experience is that it depends on why you serialize the data. I like Storable for the state of the program, including things like window size / position. I prefer YAML for configuration data or anything you might want to exchange with another copy of the application. (i.e. share between users - the Storable file may not be read by the user with a different version of Perl or Storable.) Storable supports graphic objects (provided that freezing / thawing is performed correctly). I'm not sure about yaml.

+1
source

All Articles