9 eval "use IO::AtomicFile";
10 plan skip_all => "IO::AtomicFile is required for this test" if $@;
12 plan skip_all => "JSON::Any is required for this test" if $@;
14 use_ok('MooseX::Storage');
22 with 'MooseX::Storage::Deferred';
24 has 'number' => (is => 'ro', isa => 'Int');
25 has 'string' => (is => 'ro', isa => 'Str');
26 has 'float' => (is => 'ro', isa => 'Num');
27 has 'array' => (is => 'ro', isa => 'ArrayRef');
28 has 'hash' => (is => 'ro', isa => 'HashRef');
29 has 'object' => (is => 'ro', isa => 'Object');
32 my $file = 'temp.json';
40 hash => { map { $_ => undef } (1 .. 10) },
41 object => Foo->new( number => 2 ),
45 $foo->store($file, { format => 'JSON', io => 'File' });
49 my $foo = Foo->load($file, { format => 'JSON', io => 'File' });
52 is($foo->number, 10, '... got the right number');
53 is($foo->string, 'foo', '... got the right string');
54 is($foo->float, 10.5, '... got the right float');
55 is_deeply($foo->array, [ 1 .. 10], '... got the right array');
56 is_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
58 isa_ok($foo->object, 'Foo');
59 is($foo->object->number, 2, '... got the right number (in the embedded object)');
63 ok(!(-e $file), '... the file has been deleted');
71 hash => { map { $_ => undef } (1 .. 10) },
72 object => Foo->new( number => 2 ),
76 $foo->store($file, { format => 'JSON', io => 'AtomicFile' });
80 my $foo = Foo->load($file, { format => 'JSON', io => 'AtomicFile' });
83 is($foo->number, 10, '... got the right number');
84 is($foo->string, 'foo', '... got the right string');
85 is($foo->float, 10.5, '... got the right float');
86 is_deeply($foo->array, [ 1 .. 10], '... got the right array');
87 is_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
89 isa_ok($foo->object, 'Foo');
90 is($foo->object->number, 2, '... got the right number (in the embedded object)');
94 ok(!(-e $file), '... the file has been deleted');