Search code examples
perlobjectmodulebackwards-compatibilitymoose

How should I maintain my object modules in Perl?


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?


Solution

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