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