2 package MooseX::Storage::Format::JSON;
10 our $VERSION = '0.03';
11 our $AUTHORITY = 'cpan:STEVAN';
17 my ( $class, $json, @args ) = @_;
18 utf8::encode($json) if utf8::is_utf8($json);
19 $class->unpack( JSON::Any->jsonToObj($json), @args );
23 my ( $self, @args ) = @_;
24 my $json = JSON::Any->objToJson( $self->pack(@args) );
25 utf8::decode($json) if !utf8::is_utf8($json) and utf8::valid($json); # if it's valid utf8 mark it as such
37 MooseX::Storage::Format::JSON
45 with Storage('format' => 'JSON');
47 has 'x' => (is => 'rw', isa => 'Int');
48 has 'y' => (is => 'rw', isa => 'Int');
52 my $p = Point->new(x => 10, y => 10);
54 ## methods to freeze/thaw into
55 ## a specified serialization format
56 ## (in this case JSON)
58 # pack the class into a JSON string
59 $p->freeze(); # { "__CLASS__" : "Point", "x" : 10, "y" : 10 }
61 # unpack the JSON string into a class
62 my $p2 = Point->thaw('{ "__CLASS__" : "Point", "x" : 10, "y" : 10 }');
84 All complex software has bugs lurking in it, and this module is no
85 exception. If you find a bug please either email me, or add the bug
90 Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
92 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
94 Yuval Kogman E<lt>yuval.kogman@iinteractive.comE<gt>
96 =head1 COPYRIGHT AND LICENSE
98 Copyright 2007-2008 by Infinity Interactive, Inc.
100 L<http://www.iinteractive.com>
102 This library is free software; you can redistribute it and/or modify
103 it under the same terms as Perl itself.