3 use Test::More tests => 6;
4 use Scalar::Util qw/blessed/;
8 sub new { bless {}, shift };
12 use overload '""' => sub { 'Ref' }, fallback => 1;
13 sub new { bless {}, shift };
19 use Mouse::TypeRegistry;
21 subtype 'Type1' => as 'Str' => where { blessed($_) };
27 subtype 'Type2' => as 'Object' => where { $_ eq 'Ref' };
34 eval { Foo->new( str_obj => Obj1->new ) };
35 like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Validation failed for 'Type1' failed with value Obj1=HASH/;
36 eval { Foo->new( obj_str => Obj1->new ) };
37 like $@, qr/Attribute \(obj_str\) does not pass the type constraint because: Validation failed for 'Type2' failed with value Obj1=HASH/;
39 eval { Foo->new( str_obj => Obj2->new ) };
40 like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Validation failed for 'Type1' failed with value Obj2=HASH/;
42 eval { Foo->new( str_obj => 'Ref' ) };
43 like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Validation failed for 'Type1' failed with value Ref/;
45 my $f1 = eval { Foo->new( obj_str => Obj2->new ) };
47 is $f1->obj_str, 'Ref';