6 use Test::More tests => 3;
19 use Mouse::Util::TypeConstraints;
23 => where { defined $_->[0] }
24 => message { ref $_ ? "ref: ". ref $_ : 'scalar' } # stringy
27 subtype 'MyObjectType'
29 => where { $_->isa('MyObject') }
31 if ( $_->isa('SomeObject') ) {
32 return 'More detailed error message';
34 elsif ( blessed $_ ) {
35 return 'Well it is an object';
44 => where { $_->isa('MyObject') }
45 => message { blessed $_ ? 'blessed' : 'scalar' }
48 has 'obj' => ( is => 'rw', isa => 'MyObjectType' );
49 has 'ar' => ( is => 'rw', isa => 'MyArrayRef' );
50 has 'nt' => ( is => 'rw', isa => 'NewType' );
54 my $obj = MyObject->new;
59 qr/Attribute \(ar\) does not pass the type constraint because: ref: ARRAY/,
60 '... got the right error message';
63 $foo->obj($foo); # Doh!
65 qr/Attribute \(obj\) does not pass the type constraint because: Well it is an object/,
66 '... got the right error message';
69 $foo->nt($foo); # scalar
71 qr/Attribute \(nt\) does not pass the type constraint because: blessed/,
72 '... got the right error message';