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