2 package MooseX::Storage::Format::JSON;
10 our $AUTHORITY = 'cpan:STEVAN';
16 my ( $class, $json, @args ) = @_;
17 local $JSON::UnMapping = 1;
18 $class->unpack( JSON::Any->jsonToObj($json), @args );
22 my ( $self, @args ) = @_;
23 local $JSON::UnMapping = 1;
24 JSON::Any->objToJson( $self->pack(@args) );
35 MooseX::Storage::Format::JSON
43 with Storage('format' => 'JSON');
45 has 'x' => (is => 'rw', isa => 'Int');
46 has 'y' => (is => 'rw', isa => 'Int');
50 my $p = Point->new(x => 10, y => 10);
52 ## methods to freeze/thaw into
53 ## a specified serialization format
54 ## (in this case JSON)
56 # pack the class into a JSON string
57 $p->freeze(); # { "__CLASS__" : "Point", "x" : 10, "y" : 10 }
59 # unpack the JSON string into a class
60 my $p2 = Point->thaw('{ "__CLASS__" : "Point", "x" : 10, "y" : 10 }');
82 All complex software has bugs lurking in it, and this module is no
83 exception. If you find a bug please either email me, or add the bug
88 Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
90 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
92 =head1 COPYRIGHT AND LICENSE
94 Copyright 2007 by Infinity Interactive, Inc.
96 L<http://www.iinteractive.com>
98 This library is free software; you can redistribute it and/or modify
99 it under the same terms as Perl itself.