2 package MooseX::Storage::Format::JSON;
15 my ( $class, $json, @args ) = @_;
16 local $JSON::UnMapping = 1;
17 $class->unpack( JSON::Any->jsonToObj($json), @args );
21 my ( $self, @args ) = @_;
22 local $JSON::UnMapping = 1;
23 JSON::Any->objToJson( $self->pack(@args) );
34 MooseX::Storage::Format::JSON
42 with Storage('format' => 'JSON');
44 has 'x' => (is => 'rw', isa => 'Int');
45 has 'y' => (is => 'rw', isa => 'Int');
49 my $p = Point->new(x => 10, y => 10);
51 ## methods to freeze/thaw into
52 ## a specified serialization format
53 ## (in this case JSON)
55 # pack the class into a JSON string
56 $p->freeze(); # { "__CLASS__" : "Point", "x" : 10, "y" : 10 }
58 # unpack the JSON string into a class
59 my $p2 = Point->thaw('{ "__CLASS__" : "Point", "x" : 10, "y" : 10 }');
81 All complex software has bugs lurking in it, and this module is no
82 exception. If you find a bug please either email me, or add the bug
87 Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
89 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
91 =head1 COPYRIGHT AND LICENSE
93 Copyright 2007 by Infinity Interactive, Inc.
95 L<http://www.iinteractive.com>
97 This library is free software; you can redistribute it and/or modify
98 it under the same terms as Perl itself.