delay loading all optional prereqs until runtime
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Format / JSON.pm
index c557872..13284c9 100644 (file)
@@ -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;