eval require instead of use
[gitmo/MooseX-Storage.git] / t / 009_do_not_serialize_lazy.t
CommitLineData
76218b46 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More 'no_plan';#tests => 6;
7use Test::Exception;
8
9BEGIN {
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
30my $p = Point->new( 'x' => $$ );
31ok( $p, "New object created" );
32
33my $href = $p->pack;
34
35ok( $href, " Object packed" );
36is( $href->{'x'}, $$, " x => $$" );
37is( $href->{'z'}, 'z', " z => z" );
38ok( not(exists($href->{'y'})), " y does not exist" );
39
b5f363ac 40is_deeply(
41 $href,
76218b46 42 { '__CLASS__' => 'Point',
43 'x' => $$,
44 'z' => 'z'
45 }, " Deep check passed" );