X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStorage%2FFormat%2FJSON.pm;h=13284c9a8c240c9e538e99f0f641153397a40002;hb=d1f98188a6568ce657a6ad45a26247b6d6a5acc1;hp=c5578728014e5b9b2835d2461355a58f3eb3e878;hpb=4f94761e9fd6f813b81a201c50aecd5bdac2a80f;p=gitmo%2FMooseX-Storage.git diff --git a/lib/MooseX/Storage/Format/JSON.pm b/lib/MooseX/Storage/Format/JSON.pm index c557872..13284c9 100644 --- a/lib/MooseX/Storage/Format/JSON.pm +++ b/lib/MooseX/Storage/Format/JSON.pm @@ -3,19 +3,23 @@ use Moose::Role; no warnings 'once'; -use JSON::Any; - requires 'pack'; requires 'unpack'; sub thaw { my ( $class, $json, @args ) = @_; + + require JSON::Any; + utf8::encode($json) if utf8::is_utf8($json); $class->unpack( JSON::Any->new->jsonToObj($json), @args ); } sub freeze { my ( $self, @args ) = @_; + + require JSON::Any; + my $json = JSON::Any->new(canonical => 1)->objToJson( $self->pack(@args) ); utf8::decode($json) if !utf8::is_utf8($json) and utf8::valid($json); # if it's valid utf8 mark it as such return $json;