Commit | Line | Data |
c1830046 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More tests => 8; |
619ab942 |
5 | use Test::Deep; |
9d3c60f5 |
6 | use Test::Fatal; |
c1830046 |
7 | |
8 | BEGIN { |
9 | use_ok('MooseX::Storage'); |
10 | } |
11 | |
12 | =pod |
13 | |
c2dae5d8 |
14 | This tests that the version and authority |
c1830046 |
15 | checks are performed upon object expansion. |
16 | |
17 | =cut |
18 | |
19 | { |
20 | package Bar; |
21 | use Moose; |
22 | use MooseX::Storage; |
c2dae5d8 |
23 | |
c1830046 |
24 | our $VERSION = '0.01'; |
25 | our $AUTHORITY = 'cpan:JRANDOM'; |
26 | |
27 | with Storage; |
c2dae5d8 |
28 | |
c1830046 |
29 | has 'number' => (is => 'ro', isa => 'Int'); |
c2dae5d8 |
30 | |
c1830046 |
31 | package Foo; |
32 | use Moose; |
33 | use MooseX::Storage; |
34 | |
35 | our $VERSION = '0.01'; |
c2dae5d8 |
36 | our $AUTHORITY = 'cpan:JRANDOM'; |
c1830046 |
37 | |
c2dae5d8 |
38 | with Storage; |
c1830046 |
39 | |
c2dae5d8 |
40 | has 'bar' => ( |
41 | is => 'ro', |
42 | isa => 'Bar' |
43 | ); |
c1830046 |
44 | } |
45 | |
46 | { |
47 | my $foo = Foo->new( |
48 | bar => Bar->new(number => 1) |
49 | ); |
50 | isa_ok( $foo, 'Foo' ); |
c2dae5d8 |
51 | |
619ab942 |
52 | cmp_deeply( |
c1830046 |
53 | $foo->pack, |
54 | { |
55 | __CLASS__ => 'Foo-0.01-cpan:JRANDOM', |
56 | bar => { |
57 | __CLASS__ => 'Bar-0.01-cpan:JRANDOM', |
58 | number => 1, |
c2dae5d8 |
59 | } |
c1830046 |
60 | }, |
61 | '... got the right frozen class' |
62 | ); |
63 | } |
64 | |
65 | { |
66 | my $foo = Foo->unpack( |
67 | { |
68 | __CLASS__ => 'Foo-0.01-cpan:JRANDOM', |
69 | bar => { |
70 | __CLASS__ => 'Bar-0.01-cpan:JRANDOM', |
71 | number => 1, |
c2dae5d8 |
72 | } |
73 | }, |
c1830046 |
74 | ); |
75 | isa_ok( $foo, 'Foo' ); |
76 | isa_ok( $foo->bar, 'Bar' ); |
77 | is( $foo->bar->number, 1 , '... got the right number too' ); |
c2dae5d8 |
78 | |
c1830046 |
79 | } |
80 | |
c2dae5d8 |
81 | Moose::Meta::Class->create('Bar', |
c1830046 |
82 | version => '0.02', |
83 | authority => 'cpan:JRANDOM', |
84 | ); |
85 | |
9d3c60f5 |
86 | ok(exception { |
c1830046 |
87 | Foo->unpack( |
88 | { |
89 | __CLASS__ => 'Foo-0.01-cpan:JRANDOM', |
90 | bar => { |
91 | __CLASS__ => 'Bar-0.01-cpan:JRANDOM', |
92 | number => 1, |
c2dae5d8 |
93 | } |
94 | } |
c1830046 |
95 | ); |
9d3c60f5 |
96 | }, '... could not unpack, versions are different ' . $@); |
c1830046 |
97 | |
c2dae5d8 |
98 | Moose::Meta::Class->create('Bar', |
c1830046 |
99 | version => '0.01', |
100 | authority => 'cpan:DSTATIC', |
101 | ); |
102 | |
9d3c60f5 |
103 | ok(exception { |
c1830046 |
104 | Foo->unpack( |
105 | { |
106 | __CLASS__ => 'Foo-0.01-cpan:JRANDOM', |
107 | bar => { |
108 | __CLASS__ => 'Bar-0.01-cpan:JRANDOM', |
109 | number => 1, |
c2dae5d8 |
110 | } |
111 | } |
c1830046 |
112 | ); |
9d3c60f5 |
113 | }, '... could not unpack, authorities are different'); |