Commit | Line | Data |
124c2ba5 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More tests => 10; |
619ab942 |
5 | use Test::Deep; |
5e5d4e28 |
6 | use File::Temp qw(tempdir); |
7 | use File::Spec::Functions; |
8 | my $dir = tempdir( CLEANUP => 1 ); |
124c2ba5 |
9 | |
10 | BEGIN { |
11 | use_ok('MooseX::Storage'); |
12 | } |
13 | |
14 | { |
15 | package Foo; |
16 | use Moose; |
17 | use MooseX::Storage; |
c2dae5d8 |
18 | |
124c2ba5 |
19 | with Storage(io => 'StorableFile'); |
c2dae5d8 |
20 | |
124c2ba5 |
21 | has 'number' => (is => 'ro', isa => 'Int'); |
22 | has 'string' => (is => 'ro', isa => 'Str'); |
c2dae5d8 |
23 | has 'float' => (is => 'ro', isa => 'Num'); |
124c2ba5 |
24 | has 'array' => (is => 'ro', isa => 'ArrayRef'); |
c2dae5d8 |
25 | has 'hash' => (is => 'ro', isa => 'HashRef'); |
26 | has 'object' => (is => 'ro', isa => 'Object'); |
124c2ba5 |
27 | } |
28 | |
5e5d4e28 |
29 | my $file = catfile($dir,'temp.storable'); |
124c2ba5 |
30 | |
31 | { |
32 | my $foo = Foo->new( |
33 | number => 10, |
34 | string => 'foo', |
35 | float => 10.5, |
36 | array => [ 1 .. 10 ], |
37 | hash => { map { $_ => undef } (1 .. 10) }, |
38 | object => Foo->new( number => 2 ), |
39 | ); |
40 | isa_ok($foo, 'Foo'); |
41 | |
42 | $foo->store($file); |
43 | } |
44 | |
45 | { |
46 | my $foo = Foo->load($file); |
47 | isa_ok($foo, 'Foo'); |
48 | |
49 | is($foo->number, 10, '... got the right number'); |
50 | is($foo->string, 'foo', '... got the right string'); |
51 | is($foo->float, 10.5, '... got the right float'); |
619ab942 |
52 | cmp_deeply($foo->array, [ 1 .. 10], '... got the right array'); |
53 | cmp_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash'); |
124c2ba5 |
54 | |
55 | isa_ok($foo->object, 'Foo'); |
56 | is($foo->object->number, 2, '... got the right number (in the embedded object)'); |
57 | } |
58 | |