remove useless shebangs in tests
[gitmo/MooseX-Storage.git] / t / 102_io_storable_file.t
CommitLineData
124c2ba5 1use strict;
2use warnings;
3
4use Test::More tests => 10;
619ab942 5use Test::Deep;
5e5d4e28 6use File::Temp qw(tempdir);
7use File::Spec::Functions;
8my $dir = tempdir( CLEANUP => 1 );
124c2ba5 9
10BEGIN {
11 use_ok('MooseX::Storage');
12}
13
14{
15 package Foo;
16 use Moose;
17 use MooseX::Storage;
b5f363ac 18
124c2ba5 19 with Storage(io => 'StorableFile');
b5f363ac 20
124c2ba5 21 has 'number' => (is => 'ro', isa => 'Int');
22 has 'string' => (is => 'ro', isa => 'Str');
b5f363ac 23 has 'float' => (is => 'ro', isa => 'Num');
124c2ba5 24 has 'array' => (is => 'ro', isa => 'ArrayRef');
b5f363ac 25 has 'hash' => (is => 'ro', isa => 'HashRef');
26 has 'object' => (is => 'ro', isa => 'Object');
124c2ba5 27}
28
5e5d4e28 29my $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