3 use Test::More tests => 12;
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::Util::TypeConstraints;
21 subtype 'Type1' => as 'Str' => where { blessed($_) };
27 subtype 'Type2' => as 'Object' => where { $_ eq 'Ref' };
33 subtype 'Type3' => as 'Object';
47 eval { Foo->new( str_obj => Obj1->new ) };
48 like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Validation failed for 'Type1' failed with value Obj1=HASH/;
49 eval { Foo->new( obj_str => Obj1->new ) };
50 like $@, qr/Attribute \(obj_str\) does not pass the type constraint because: Validation failed for 'Type2' failed with value Obj1=HASH/;
52 eval { Foo->new( str_obj => Obj2->new ) };
53 like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Validation failed for 'Type1' failed with value Obj2=HASH/;
55 eval { Foo->new( str_obj => 'Ref' ) };
56 like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Validation failed for 'Type1' failed with value Ref/;
58 my $f1 = eval { Foo->new( obj_str => Obj2->new ) };
60 is $f1->obj_str, 'Ref';
62 my $f2 = eval { Foo->new( as_only => Obj1->new ) };
64 is ref($f2->as_only), 'Obj1';
66 my $f3 = eval { Foo->new( any => Obj1->new ) };
69 is ref($f3->any), 'Obj1';
71 my $f4 = eval { Foo->new( any => 'YATTA' ) };