MooseX::Storage::Format::JSONpm - a format role for MooseX::Storage using JSON.pm
version 0.093094
package Point; use Moose; use MooseX::Storage; with Storage(format => 'JSONpm'); has 'x' => (is => 'rw', isa => 'Int'); has 'y' => (is => 'rw', isa => 'Int'); 1; my $p = Point->new(x => 10, y => 10); # pack the class into a JSON string my $json = $p->freeze(); # { "__CLASS__" : "Point", "x" : 10, "y" : 10 } # unpack the JSON string into an object my $p2 = Point->thaw($json);
...in other words, it can be used as a drop-in replacement for MooseX::Storage::Format::JSON. However, it can also be parameterized:
package Point; use Moose; use MooseX::Storage; with Storage(format => [ JSONpm => { json_opts => { pretty => 1 } } ]);
At present, json_opts is the only parameter, and is used when calling the to_json and from_json routines provided by the JSON library. Default values are merged into the given hashref (with explict values taking priority). The defaults are as follows:
json_opts
to_json
from_json
{ ascii => 1 }
This library should run on perls released even a long time ago. It should work on any version of perl released in the last five years.
Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.
my $json = $obj->freeze;
my $obj = Class->thaw($json)
Thanks to Stevan Little, Chris Prather, and Yuval Kogman, from whom I cribbed this code -- from MooseX::Storage::Format::JSON.
Ricardo SIGNES <cpan@semiotic.systems>
Ricardo Signes <rjbs@semiotic.systems>
This software is copyright (c) 2022 by Ricardo SIGNES.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install MooseX::Storage::Format::JSONpm, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Storage::Format::JSONpm
CPAN shell
perl -MCPAN -e shell install MooseX::Storage::Format::JSONpm
For more information on module installation, please visit the detailed CPAN module installation guide.