问题
I use MooseX::Storage for serialization of Moose objects. Can I use it for serialization of multiple Moose objects to the same file, or more specifically, an array or a hash of Moose objects?
I guess I can define another Moose objects ('array_of_myobj') but this isn't very elegant.
So, how would you recommend to serialize an array (or a hash) of Moose objects?
回答1:
You don't have to let MooseX::Storage manage your file IO just because it's available. You could use it to pack your objects into hashrefs and then dump them with YAML or Storable or whatever yourself. This is why MooseX::Storage distinguishes between three levels of serialization.
That said, I disagree that it is inelegant to make a single top-level object that contains all the other objects you want to serialize in a given context.
来源:https://stackoverflow.com/questions/4010327/how-should-i-serialize-an-array-of-moose-objects