6 use Test::More tests => 11;
8 use File::Temp qw(tempdir);
9 use File::Spec::Functions;
10 my $dir = tempdir( CLEANUP => 1 );
13 use_ok('MooseX::Storage');
21 with Storage(io => 'StorableFile');
23 has 'number' => (is => 'ro', isa => 'Int');
24 has 'string' => (is => 'rw', isa => 'Str');
25 has 'float' => (is => 'ro', isa => 'Num');
26 has 'array' => (is => 'ro', isa => 'ArrayRef');
27 has 'hash' => (is => 'ro', isa => 'HashRef');
28 has 'object' => (is => 'ro', isa => 'Object');
30 ## add some custom freeze/thaw hooks here ...
33 my ( $class, $data ) = @_;
34 my $self = $class->unpack( $data );
35 $self->string("Hello World");
40 my ( $self, @args ) = @_;
41 my $data = $self->pack(@args);
42 $data->{string} = "HELLO WORLD";
48 my $file = catfile($dir,'temp.storable');
56 hash => { map { $_ => undef } (1 .. 10) },
57 object => Foo->new( number => 2 ),
63 # check our custom freeze hook fired ...
64 my $data = Storable::retrieve($file);
71 'string' => 'HELLO WORLD',
72 'array' => [ 1 .. 10],
73 'hash' => { map { $_ => undef } 1 .. 10 },
79 '... got the data struct we expected'
85 my $foo = Foo->load($file);
88 ## check our custom thaw hook fired
89 is($foo->string, 'Hello World', '... got the right string');
91 is($foo->number, 10, '... got the right number');
92 is($foo->float, 10.5, '... got the right float');
93 is_deeply($foo->array, [ 1 .. 10], '... got the right array');
94 is_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
96 isa_ok($foo->object, 'Foo');
97 is($foo->object->number, 2, '... got the right number (in the embedded object)');