8 use File::Temp qw(tempdir);
9 use File::Spec::Functions;
10 my $dir = tempdir( CLEANUP => 1 );
13 'JSON::Any' => 0.01, # skip all if not installed
14 'IO::AtomicFile' => 0.01,
19 use_ok('MooseX::Storage');
27 with Storage(format => 'JSON', io => 'AtomicFile');
29 has 'number' => (is => 'ro', isa => 'Int');
30 has 'string' => (is => 'ro', isa => 'Str');
31 has 'float' => (is => 'ro', isa => 'Num');
32 has 'array' => (is => 'ro', isa => 'ArrayRef');
33 has 'hash' => (is => 'ro', isa => 'HashRef');
34 has 'object' => (is => 'ro', isa => 'Object');
37 my $file = catfile($dir,'temp.json');
45 hash => { map { $_ => undef } (1 .. 10) },
46 object => Foo->new( number => 2 ),
54 my $foo = Foo->load($file);
57 is($foo->number, 10, '... got the right number');
58 is($foo->string, 'foo', '... got the right string');
59 is($foo->float, 10.5, '... got the right float');
60 cmp_deeply($foo->array, [ 1 .. 10], '... got the right array');
61 cmp_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
63 isa_ok($foo->object, 'Foo');
64 is($foo->object->number, 2, '... got the right number (in the embedded object)');