4 use Test::More tests => 22;
8 use_ok('MooseX::Storage');
19 has 'number' => ( is => 'ro', isa => 'Maybe[Int]' );
20 has 'string' => ( is => 'ro', isa => 'Maybe[Str]' );
21 has 'boolean' => ( is => 'ro', isa => 'Maybe[Bool]' );
22 has 'float' => ( is => 'ro', isa => 'Maybe[Num]' );
23 has 'array' => ( is => 'ro', isa => 'Maybe[ArrayRef]' );
24 has 'hash' => ( is => 'ro', isa => 'Maybe[HashRef]' );
25 has 'object' => ( is => 'ro', isa => 'Maybe[Foo]' );
35 hash => { map { $_ => undef } ( 1 .. 10 ) },
36 object => Foo->new( number => 2 ),
38 isa_ok( $foo, 'Foo' );
49 hash => { map { $_ => undef } ( 1 .. 10 ) },
55 '... got the right frozen class'
60 my $foo = Foo->unpack(
68 hash => { map { $_ => undef } ( 1 .. 10 ) },
75 isa_ok( $foo, 'Foo' );
77 is( $foo->number, 10, '... got the right number' );
78 is( $foo->string, 'foo', '... got the right string' );
79 ok( $foo->boolean, '... got the right boolean' );
80 is( $foo->float, 10.5, '... got the right float' );
81 cmp_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
84 { map { $_ => undef } ( 1 .. 10 ) },
85 '... got the right hash'
88 isa_ok( $foo->object, 'Foo' );
89 is( $foo->object->number, 2,
90 '... got the right number (in the embedded object)' );
98 use Moose::Util::TypeConstraints;
101 use Scalar::Util 'looks_like_number';
111 => where { "$_" =~ /\.5$/ };
115 => where { lc($_) eq 'foo' };
119 => where { scalar grep { looks_like_number($_) } @{$_} };
123 => where { scalar grep { !defined($_) } values %{$_} };
125 has 'number' => ( is => 'ro', isa => 'Maybe[Natural]' );
126 has 'string' => ( is => 'ro', isa => 'Maybe[FooString]' );
127 has 'float' => ( is => 'ro', isa => 'Maybe[HalfNum]' );
128 has 'array' => ( is => 'ro', isa => 'Maybe[IntArray]' );
129 has 'hash' => ( is => 'ro', isa => 'Maybe[UndefHash]' );
130 has 'object' => ( is => 'ro', isa => 'Maybe[Foo]' );
138 array => [ 1 .. 10 ],
139 hash => { map { $_ => undef } ( 1 .. 10 ) },
140 object => Foo->new( number => 2 ),
142 isa_ok( $foo, 'Foo' );
151 array => [ 1 .. 10 ],
152 hash => { map { $_ => undef } ( 1 .. 10 ) },
158 '... got the right frozen class'
163 my $foo = Foo->unpack(
169 array => [ 1 .. 10 ],
170 hash => { map { $_ => undef } ( 1 .. 10 ) },
177 isa_ok( $foo, 'Foo' );
179 is( $foo->number, 10, '... got the right number' );
180 is( $foo->string, 'foo', '... got the right string' );
181 is( $foo->float, 10.5, '... got the right float' );
182 cmp_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
185 { map { $_ => undef } ( 1 .. 10 ) },
186 '... got the right hash'
189 isa_ok( $foo->object, 'Foo' );
190 is( $foo->object->number, 2,
191 '... got the right number (in the embedded object)' );