18 use Moose::Util::TypeConstraints;
22 => where { defined $_->[0] }
23 => message { ref $_ ? "ref: ". ref $_ : 'scalar' } # stringy
26 subtype 'MyObjectType'
28 => where { $_->isa('MyObject') }
30 if ( $_->isa('SomeObject') ) {
31 return 'More detailed error message';
33 elsif ( blessed $_ ) {
34 return 'Well it is an object';
43 => where { $_->isa('MyObject') }
44 => message { blessed $_ ? 'blessed' : 'scalar' }
47 has 'obj' => ( is => 'rw', isa => 'MyObjectType' );
48 has 'ar' => ( is => 'rw', isa => 'MyArrayRef' );
49 has 'nt' => ( is => 'rw', isa => 'NewType' );
53 my $obj = MyObject->new;
57 }, qr/Attribute \(ar\) does not pass the type constraint because: ref: ARRAY/, '... got the right error message' );
60 $foo->obj($foo); # Doh!
61 }, qr/Attribute \(obj\) does not pass the type constraint because: Well it is an object/, '... got the right error message' );
64 $foo->nt($foo); # scalar
65 }, qr/Attribute \(nt\) does not pass the type constraint because: blessed/, '... got the right error message' );