3 use Test::More tests => 13;
9 use MouseX::Types -declare => [qw/ Baz Type1 Type2 /];
10 use MouseX::Types::Mouse qw( ArrayRef );
12 type Baz, where { defined($_) && $_ eq 'Baz' };
13 coerce Baz, from ArrayRef, via { 'Baz' };
15 type Type1, where { defined($_) && $_ eq 'Name' };
16 coerce Type1, from 'Str', via { 'Names' };
18 type Type2, where { defined($_) && $_ eq 'Group' };
19 coerce Type2, from 'Str', via { 'Name' };
26 use MouseX::Types::Mouse qw( Str Undef );
27 BEGIN { Types->import(qw( Baz Type1 )) }
28 has 'bar' => ( is => 'rw', isa => Str | Baz | Undef, coerce => 1 );
32 Foo->new( bar => +{} );
34 ok $@, 'not got an object';
37 isa_ok(Foo->new( bar => undef ), 'Foo');
39 ok !$@, 'got an object 1';
42 isa_ok(Foo->new( bar => 'foo' ), 'Foo');
45 ok !$@, 'got an object 2';
53 is $f->bar, 'Baz', 'bar is baz (coerce from ArrayRef)';
59 is $f->bar, 'hoge', 'bar is hoge';
65 is $f->bar, undef, 'bar is undef';
71 BEGIN { Types->import(qw( Type1 Type2 )) }
72 has 'foo' => ( is => 'rw', isa => Type1 | Type2 , coerce => 1 );
75 my $foo = Bar->new( foo => 'aaa' );
76 ok $foo, 'got an object 3';
77 is $foo->foo, 'Name', 'foo is Name';