6 use Test::More tests => 11;
10 use_ok('MooseX::Storage');
18 with Storage(io => 'StorableFile');
20 has 'number' => (is => 'ro', isa => 'Int');
21 has 'string' => (is => 'rw', isa => 'Str');
22 has 'float' => (is => 'ro', isa => 'Num');
23 has 'array' => (is => 'ro', isa => 'ArrayRef');
24 has 'hash' => (is => 'ro', isa => 'HashRef');
25 has 'object' => (is => 'ro', isa => 'Object');
27 ## add some custom freeze/thaw hooks here ...
30 my ( $class, $data ) = @_;
31 my $self = $class->unpack( $data );
32 $self->string("Hello World");
37 my ( $self, @args ) = @_;
38 my $data = $self->pack(@args);
39 $data->{string} = "HELLO WORLD";
45 my $file = 'temp.storable';
53 hash => { map { $_ => undef } (1 .. 10) },
54 object => Foo->new( number => 2 ),
60 # check our custom freeze hook fired ...
61 my $data = Storable::retrieve($file);
68 'string' => 'HELLO WORLD',
69 'array' => [ 1 .. 10],
70 'hash' => { map { $_ => undef } 1 .. 10 },
76 '... got the data struct we expected'
82 my $foo = Foo->load($file);
85 ## check our custom thaw hook fired
86 is($foo->string, 'Hello World', '... got the right string');
88 is($foo->number, 10, '... got the right number');
89 is($foo->float, 10.5, '... got the right float');
90 is_deeply($foo->array, [ 1 .. 10], '... got the right array');
91 is_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
93 isa_ok($foo->object, 'Foo');
94 is($foo->object->number, 2, '... got the right number (in the embedded object)');