6 use Test::More tests => 11;
9 use File::Temp qw(tempdir);
10 use File::Spec::Functions;
11 my $dir = tempdir( CLEANUP => 1 );
14 use_ok('MooseX::Storage');
22 with Storage(io => 'StorableFile');
24 has 'number' => (is => 'ro', isa => 'Int');
25 has 'string' => (is => 'rw', isa => 'Str');
26 has 'float' => (is => 'ro', isa => 'Num');
27 has 'array' => (is => 'ro', isa => 'ArrayRef');
28 has 'hash' => (is => 'ro', isa => 'HashRef');
29 has 'object' => (is => 'ro', isa => 'Object');
31 ## add some custom freeze/thaw hooks here ...
34 my ( $class, $data ) = @_;
35 my $self = $class->unpack( $data );
36 $self->string("Hello World");
41 my ( $self, @args ) = @_;
42 my $data = $self->pack(@args);
43 $data->{string} = "HELLO WORLD";
49 my $file = catfile($dir,'temp.storable');
57 hash => { map { $_ => undef } (1 .. 10) },
58 object => Foo->new( number => 2 ),
64 # check our custom freeze hook fired ...
65 my $data = Storable::retrieve($file);
72 'string' => 'HELLO WORLD',
73 'array' => [ 1 .. 10],
74 'hash' => { map { $_ => undef } 1 .. 10 },
80 '... got the data struct we expected'
86 my $foo = Foo->load($file);
89 ## check our custom thaw hook fired
90 is($foo->string, 'Hello World', '... got the right string');
92 is($foo->number, 10, '... got the right number');
93 is($foo->float, 10.5, '... got the right float');
94 cmp_deeply($foo->array, [ 1 .. 10], '... got the right array');
95 cmp_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
97 isa_ok($foo->object, 'Foo');
98 is($foo->object->number, 2, '... got the right number (in the embedded object)');