Commit | Line | Data |
913d96dd |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More no_plan => 1; |
7 | |
8 | BEGIN { |
9 | use_ok('MooseX::Storage'); |
10 | } |
11 | |
12 | { |
13 | package Bar; |
14 | use Moose; |
15 | use MooseX::Storage; |
16 | |
17 | with Storage; |
18 | |
19 | has 'baz' => (is => 'ro', isa => 'Int'); |
20 | |
21 | package Foo; |
22 | use Moose; |
23 | use MooseX::Storage; |
24 | |
25 | with Storage; |
26 | |
27 | has 'bars' => ( |
28 | is => 'ro', |
29 | isa => 'ArrayRef' |
30 | ); |
31 | } |
32 | |
33 | { |
34 | my $foo = Foo->new( |
35 | bars => [ map { Bar->new(baz => $_) } (1 .. 10) ] |
36 | ); |
37 | isa_ok( $foo, 'Foo' ); |
38 | |
39 | is_deeply( |
40 | $foo->pack, |
41 | { |
42 | __class__ => 'Foo', |
43 | bars => [ |
44 | map { |
45 | { |
46 | __class__ => 'Bar', |
47 | baz => $_, |
48 | } |
49 | } (1 .. 10) |
50 | ], |
51 | }, |
52 | '... got the right frozen class' |
53 | ); |
54 | } |
55 | |
56 | { |
57 | my $foo = Foo->unpack( |
58 | { |
59 | __class__ => 'Foo', |
60 | bars => [ |
61 | map { |
62 | { |
63 | __class__ => 'Bar', |
64 | baz => $_, |
65 | } |
66 | } (1 .. 10) |
67 | ], |
68 | } |
69 | ); |
70 | isa_ok( $foo, 'Foo' ); |
71 | |
72 | foreach my $i (1 .. scalar @{$foo->bars}) { |
73 | isa_ok($foo->bars->[$i - 1], 'Bar'); |
74 | is($foo->bars->[$i - 1]->baz, $i, "... got the right baz ($i) in the Bar in Foo"); |
75 | } |
76 | } |