Commit | Line | Data |
e59193fb |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More no_plan => 1; |
7 | |
ec9c1923 |
8 | BEGIN { |
9 | use_ok('MooseX::Storage'); |
10 | } |
11 | |
e59193fb |
12 | { |
b5384d08 |
13 | |
e59193fb |
14 | package Foo; |
15 | use Moose; |
16 | use MooseX::Storage; |
b5384d08 |
17 | |
913d96dd |
18 | with Storage; |
b5384d08 |
19 | |
20 | has 'number' => ( is => 'ro', isa => 'Int' ); |
21 | has 'string' => ( is => 'ro', isa => 'Str' ); |
22 | has 'float' => ( is => 'ro', isa => 'Num' ); |
23 | has 'array' => ( is => 'ro', isa => 'ArrayRef' ); |
24 | has 'hash' => ( is => 'ro', isa => 'HashRef' ); |
e1bb45ff |
25 | has 'object' => ( is => 'ro', isa => 'Foo' ); |
e59193fb |
26 | } |
27 | |
ec9c1923 |
28 | { |
a23e18d7 |
29 | my $foo = Foo->new( |
30 | number => 10, |
31 | string => 'foo', |
32 | float => 10.5, |
33 | array => [ 1 .. 10 ], |
b5384d08 |
34 | hash => { map { $_ => undef } ( 1 .. 10 ) }, |
35 | object => Foo->new( number => 2 ), |
36 | ); |
37 | isa_ok( $foo, 'Foo' ); |
ec9c1923 |
38 | |
39 | is_deeply( |
40 | $foo->pack, |
41 | { |
ba5bba75 |
42 | __CLASS__ => 'Foo', |
ec9c1923 |
43 | number => 10, |
44 | string => 'foo', |
45 | float => 10.5, |
46 | array => [ 1 .. 10 ], |
47 | hash => { map { $_ => undef } ( 1 .. 10 ) }, |
48 | object => { |
ba5bba75 |
49 | __CLASS__ => 'Foo', |
ec9c1923 |
50 | number => 2 |
51 | }, |
52 | }, |
53 | '... got the right frozen class' |
a23e18d7 |
54 | ); |
a23e18d7 |
55 | } |
56 | |
57 | { |
ec9c1923 |
58 | my $foo = Foo->unpack( |
59 | { |
ba5bba75 |
60 | __CLASS__ => 'Foo', |
ec9c1923 |
61 | number => 10, |
62 | string => 'foo', |
63 | float => 10.5, |
64 | array => [ 1 .. 10 ], |
65 | hash => { map { $_ => undef } ( 1 .. 10 ) }, |
66 | object => { |
ba5bba75 |
67 | __CLASS__ => 'Foo', |
ec9c1923 |
68 | number => 2 |
69 | }, |
70 | } |
b5384d08 |
71 | ); |
72 | isa_ok( $foo, 'Foo' ); |
a23e18d7 |
73 | |
b5384d08 |
74 | is( $foo->number, 10, '... got the right number' ); |
75 | is( $foo->string, 'foo', '... got the right string' ); |
76 | is( $foo->float, 10.5, '... got the right float' ); |
77 | is_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' ); |
78 | is_deeply( |
79 | $foo->hash, |
80 | { map { $_ => undef } ( 1 .. 10 ) }, |
81 | '... got the right hash' |
82 | ); |
a23e18d7 |
83 | |
b5384d08 |
84 | isa_ok( $foo->object, 'Foo' ); |
85 | is( $foo->object->number, 2, |
86 | '... got the right number (in the embedded object)' ); |
a23e18d7 |
87 | } |