bump to latest version of bundle
[gitmo/MooseX-Storage.git] / t / 100_io.t
CommitLineData
ec9c1923 1use strict;
2use warnings;
3
4fa64e86 4use Test::More;
619ab942 5use Test::Deep;
08d0f48e 6use File::Temp qw(tempdir);
5e5d4e28 7use File::Spec::Functions;
cfd008fa 8my $dir = tempdir;
ec9c1923 9
0b173188 10use Test::Requires {
11 'JSON::Any' => 0.01, # skip all if not installed
12};
13
14BEGIN {
15 plan tests => 10;
ec9c1923 16 use_ok('MooseX::Storage');
17}
18
19{
20 package Foo;
21 use Moose;
22 use MooseX::Storage;
c2dae5d8 23
ec9c1923 24 with Storage(format => 'JSON', io => 'File');
c2dae5d8 25
ec9c1923 26 has 'number' => (is => 'ro', isa => 'Int');
27 has 'string' => (is => 'ro', isa => 'Str');
c2dae5d8 28 has 'float' => (is => 'ro', isa => 'Num');
ec9c1923 29 has 'array' => (is => 'ro', isa => 'ArrayRef');
c2dae5d8 30 has 'hash' => (is => 'ro', isa => 'HashRef');
8b2ba857 31 has 'object' => (is => 'ro', isa => 'Object');
ec9c1923 32}
33
5e5d4e28 34my $file = catfile( $dir, 'temp.json' );
ec9c1923 35
36{
37 my $foo = Foo->new(
38 number => 10,
39 string => 'foo',
40 float => 10.5,
41 array => [ 1 .. 10 ],
42 hash => { map { $_ => undef } (1 .. 10) },
8b2ba857 43 object => Foo->new( number => 2 ),
ec9c1923 44 );
45 isa_ok($foo, 'Foo');
46
47 $foo->store($file);
48}
49
50{
51 my $foo = Foo->load($file);
52 isa_ok($foo, 'Foo');
53
54 is($foo->number, 10, '... got the right number');
55 is($foo->string, 'foo', '... got the right string');
56 is($foo->float, 10.5, '... got the right float');
619ab942 57 cmp_deeply($foo->array, [ 1 .. 10], '... got the right array');
58 cmp_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
ec9c1923 59
60 isa_ok($foo->object, 'Foo');
61 is($foo->object->number, 2, '... got the right number (in the embedded object)');
62}
63