8 use File::Spec::Functions;
13 'IO::AtomicFile' => 0.01, # skip all if not installed
19 use_ok('MooseX::Storage');
27 with 'MooseX::Storage::Deferred';
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 ),
50 $foo->store($file, { format => 'JSON', io => 'File' });
54 my $foo = Foo->load($file, { format => 'JSON', io => '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 is_deeply($foo->array, [ 1 .. 10], '... got the right array');
61 is_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)');
68 ok(!(-e $file), '... the file has been deleted');
76 hash => { map { $_ => undef } (1 .. 10) },
77 object => Foo->new( number => 2 ),
81 $foo->store($file, { format => 'JSON', io => 'AtomicFile' });
85 my $foo = Foo->load($file, { format => 'JSON', io => 'AtomicFile' });
88 is($foo->number, 10, '... got the right number');
89 is($foo->string, 'foo', '... got the right string');
90 is($foo->float, 10.5, '... got the right float');
91 is_deeply($foo->array, [ 1 .. 10], '... got the right array');
92 is_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
94 isa_ok($foo->object, 'Foo');
95 is($foo->object->number, 2, '... got the right number (in the embedded object)');