7 use File::Temp qw(tempdir);
8 use File::Spec::Functions;
12 'JSON::Any' => 0.01, # skip all if not installed
17 use_ok('MooseX::Storage');
25 with Storage(format => 'JSON', io => 'File');
27 has 'number' => (is => 'ro', isa => 'Int');
28 has 'string' => (is => 'ro', isa => 'Str');
29 has 'float' => (is => 'ro', isa => 'Num');
30 has 'array' => (is => 'ro', isa => 'ArrayRef');
31 has 'hash' => (is => 'ro', isa => 'HashRef');
32 has 'object' => (is => 'ro', isa => 'Object');
35 my $file = catfile( $dir, 'temp.json' );
43 hash => { map { $_ => undef } (1 .. 10) },
44 object => Foo->new( number => 2 ),
52 my $foo = Foo->load($file);
55 is($foo->number, 10, '... got the right number');
56 is($foo->string, 'foo', '... got the right string');
57 is($foo->float, 10.5, '... got the right float');
58 is_deeply($foo->array, [ 1 .. 10], '... got the right array');
59 is_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
61 isa_ok($foo->object, 'Foo');
62 is($foo->object->number, 2, '... got the right number (in the embedded object)');