How should I serialize an array of Moose objects?

一笑奈何 提交于 2019-12-23 17:11:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!