6 use Test::More tests => 22;
10 use_ok('MooseX::Storage');
21 has 'number' => ( is => 'ro', isa => 'Maybe[Int]' );
22 has 'string' => ( is => 'ro', isa => 'Maybe[Str]' );
23 has 'boolean' => ( is => 'ro', isa => 'Maybe[Bool]' );
24 has 'float' => ( is => 'ro', isa => 'Maybe[Num]' );
25 has 'array' => ( is => 'ro', isa => 'Maybe[ArrayRef]' );
26 has 'hash' => ( is => 'ro', isa => 'Maybe[HashRef]' );
27 has 'object' => ( is => 'ro', isa => 'Maybe[Foo]' );
37 hash => { map { $_ => undef } ( 1 .. 10 ) },
38 object => Foo->new( number => 2 ),
40 isa_ok( $foo, 'Foo' );
51 hash => { map { $_ => undef } ( 1 .. 10 ) },
57 '... got the right frozen class'
62 my $foo = Foo->unpack(
70 hash => { map { $_ => undef } ( 1 .. 10 ) },
77 isa_ok( $foo, 'Foo' );
79 is( $foo->number, 10, '... got the right number' );
80 is( $foo->string, 'foo', '... got the right string' );
81 ok( $foo->boolean, '... got the right boolean' );
82 is( $foo->float, 10.5, '... got the right float' );
83 cmp_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
86 { map { $_ => undef } ( 1 .. 10 ) },
87 '... got the right hash'
90 isa_ok( $foo->object, 'Foo' );
91 is( $foo->object->number, 2,
92 '... got the right number (in the embedded object)' );
100 use Moose::Util::TypeConstraints;
103 use Scalar::Util 'looks_like_number';
113 => where { "$_" =~ /\.5$/ };
117 => where { lc($_) eq 'foo' };
121 => where { scalar grep { looks_like_number($_) } @{$_} };
125 => where { scalar grep { !defined($_) } values %{$_} };
127 has 'number' => ( is => 'ro', isa => 'Maybe[Natural]' );
128 has 'string' => ( is => 'ro', isa => 'Maybe[FooString]' );
129 has 'float' => ( is => 'ro', isa => 'Maybe[HalfNum]' );
130 has 'array' => ( is => 'ro', isa => 'Maybe[IntArray]' );
131 has 'hash' => ( is => 'ro', isa => 'Maybe[UndefHash]' );
132 has 'object' => ( is => 'ro', isa => 'Maybe[Foo]' );
140 array => [ 1 .. 10 ],
141 hash => { map { $_ => undef } ( 1 .. 10 ) },
142 object => Foo->new( number => 2 ),
144 isa_ok( $foo, 'Foo' );
153 array => [ 1 .. 10 ],
154 hash => { map { $_ => undef } ( 1 .. 10 ) },
160 '... got the right frozen class'
165 my $foo = Foo->unpack(
171 array => [ 1 .. 10 ],
172 hash => { map { $_ => undef } ( 1 .. 10 ) },
179 isa_ok( $foo, 'Foo' );
181 is( $foo->number, 10, '... got the right number' );
182 is( $foo->string, 'foo', '... got the right string' );
183 is( $foo->float, 10.5, '... got the right float' );
184 cmp_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
187 { map { $_ => undef } ( 1 .. 10 ) },
188 '... got the right hash'
191 isa_ok( $foo->object, 'Foo' );
192 is( $foo->object->number, 2,
193 '... got the right number (in the embedded object)' );