Recently we had in our mailing list a question by Jakob Voss if Catmandu supports versioning of records. Indeed we do! In this post I’ll give an example what is possible using the Catmandu::Plugin modules developed by Nicolas Steenlant.
First, lets create a sample application in Perl to store some records in an in-memory hash for test purposes:
First we store in a record with id ‘001’ a ‘John Doe’ and then we overwrite this record with ‘John Moo’. As result you should see only the version ‘John Moo’ printed on screen.
To add versioning we have to edit the initiation of the Hash and add a ‘Versioning’ plugin to the ‘data’ bag. As you may recall ‘data’ is the default name of the storage container in your Catmandu::Store. Using the get_history method all the versions of your records can be retrieved.
Or, you can get one particular version with the ‘get_version’ method:
Or, the previous version with ‘get_previous_version’:
Sometimes you don’t want to create a new version records when nothing changed to the data except for some date field for instance. This can be set using the ‘version_compare_ignore’ field when creating a store:
Using this setting, new versions will only be created when any field except ‘access_date’ will change in value.