Commit | Line | Data |
76218b46 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More 'no_plan';#tests => 6; |
619ab942 |
5 | use Test::Deep; |
9d3c60f5 |
6 | use Test::Fatal; |
76218b46 |
7 | |
8 | BEGIN { |
9 | use_ok('MooseX::Storage'); |
10 | } |
11 | |
12 | { package Point; |
13 | use Moose; |
14 | use MooseX::Storage; |
15 | |
16 | with Storage( traits => [qw|OnlyWhenBuilt|] ); |
17 | |
18 | has 'x' => (is => 'rw', lazy_build => 1 ); |
19 | has 'y' => (is => 'rw', lazy_build => 1 ); |
20 | has 'z' => (is => 'rw', builder => '_build_z' ); |
c2dae5d8 |
21 | |
22 | |
76218b46 |
23 | sub _build_x { 'x' } |
24 | sub _build_y { 'y' } |
25 | sub _build_z { 'z' } |
26 | |
27 | } |
28 | |
29 | my $p = Point->new( 'x' => $$ ); |
30 | ok( $p, "New object created" ); |
31 | |
32 | my $href = $p->pack; |
33 | |
34 | ok( $href, " Object packed" ); |
35 | is( $href->{'x'}, $$, " x => $$" ); |
36 | is( $href->{'z'}, 'z', " z => z" ); |
37 | ok( not(exists($href->{'y'})), " y does not exist" ); |
38 | |
c2dae5d8 |
39 | cmp_deeply( |
40 | $href, |
76218b46 |
41 | { '__CLASS__' => 'Point', |
42 | 'x' => $$, |
43 | 'z' => 'z' |
44 | }, " Deep check passed" ); |