开发者

How should I maintain my object modules in Perl?

开发者 https://www.devze.com 2023-01-20 04:48 出处:网络
I\'m writing some object module in Perl using Moose. I use to store instances of created objects then use them.

I'm writing some object module in Perl using Moose. I use to store instances of created objects then use them.

The basic representation of my object's data remains the same, but from time to time I add more functionalities - e.g. class methods or object methods.

Can I continue using my stored objects, which were created with an earlier version of the module, with the new functionalities? Or must I create the objects again every time I change the mod开发者_如何学运维ule?

What is the common paradigm for developing an object module where the basic data structure does not change but functionalities do?


As long as the data structure doesn't change, you should be fine: the data is slurped and reblessed into your class' namespace: this ensures new methods would be available on that data.

BEWARE changing the data structure though!

I don't see much wrong with it, although for some uses you could just use a database to store your data, and access it in a OO fashion using one of the many ORM (DBIx::Class, Fey::ORM or whichever).


Give KiokuDB a whirl. It might be just what you want; according to the site linked:

"KiokuDB is a Moose based object oriented persistence frontend for a number of storage backends."


I second the recommendation for looking at KiokuDB.

In addition to transparent serialization of Moose objects to a graph store, it also has a facility for handling transitions between Class versions. Effectively you can define a translation routine to go from version 0.1 to 0.2 of your class and hand the migration off to it. KiokuDB will execute this routine and allow you to re-store the result.

0

精彩评论

暂无评论...
验证码 换一张
取 消