Pantry::Role::Serializable - A role to save/load data to/from JSON files
version 0.011
with 'Pantry::Role::Serializable' => { freezer => '_freeze', thawer => '_thaw', };
This parameterizable Moose role provides methods for saving/loading Pantry objects as JSON.
my $obj = $class->new_from_file( $path );
Constructs a new object from JSON data found in the given file.
$obj->save_as( $path );
Stores object data as JSON in a file at the given path location. Attributes with leading underscores are considered "private" and are omitted.
Customizing the serialization behavior can be done with the optional freezer and thawer role parameters. If either freezer or thawer is omitted, data will not be modified during saving/loading (respectively), except that private attributes are always omitted when saving.
freezer
thawer
This role parameter takes the name of a method to use for modifying the object data during freezing. It takes a hashref of data representing the object's attributes (excluding any private attributes) and must return a hashref of data which will be serialized as JSON.
This role parameter takes the name of a method to use for modifying the object data during thawing. It takes a hashref of data deserialized from JSON and must return a hashref of data suitable for passing to the object constructor.
MooseX::Storage -- this didn't quite meet my needs as it
mandates a __CLASS__ key which causes problems when Chef consumes saved data
__CLASS__
David Golden <dagolden@cpan.org>
This software is Copyright (c) 2011 by David Golden.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
To install Pantry, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pantry
CPAN shell
perl -MCPAN -e shell install Pantry
For more information on module installation, please visit the detailed CPAN module installation guide.