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