MooseX::Storage

package Point;
use Moose;
use MooseX::Storage;

our $VERSION = '0.01';

with Storage('format' => 'JSON', 'io' => 'File');

has 'x' => (is => 'rw', isa => 'Int');
has 'y' => (is => 'rw', isa => 'Int');

1;

my $p = Point->new(x => 10, y => 10);
$p->pack(); # { __CLASS__ => 'Point-0.01', x => 10, y => 10 }
my $p2 = Point->unpack({ __CLASS__ => 'Point-0.01', x => 10, y => 10 });
$p->freeze(); # { "__CLASS__" : "Point-0.01", "x" : 10, "y" : 10 }
my $p2 = Point->thaw('{ "__CLASS__" : "Point-0.01", "x" : 10, "y" : 10 }');
$p->store('my_point.json');
my $p2 = Point->load('my_point.json');