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