views:

78

answers:

3

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 module?

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

+2  A: 

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).

mfontani
Moose based object's Data structures rarely change. They're typically a hash and will remain a hash. You'll only really get into trouble when you delete keys (attribute slots) across class versions.
perigrin
So, when I serialize a Moose object (using `nstore`, for example), only the data (i.e. attributes) actually get serialized, right?
David B
True of most storables, yes.
mfontani
+1  A: 

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."

Sir Robert
+1  A: 

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.

perigrin