6 use Test::More no_plan => 1;
21 use Moose::Util::TypeConstraints;
25 => where { defined $_->[0] }
26 => message { ref $_ ? "ref: ". ref $_ : 'scalar' } # stringy
29 subtype 'MyObjectType'
31 => where { $_->isa('MyObject') }
33 if ( $_->isa('SomeObject') ) {
34 return 'More detailed error message';
36 elsif ( blessed $_ ) {
37 return 'Well it is an object';
46 => where { $_->isa('MyObject') }
47 => message { blessed $_ ? 'blessed' : 'scalar' }
50 has 'obj' => ( is => 'rw', isa => 'MyObjectType' );
51 has 'ar' => ( is => 'rw', isa => 'MyArrayRef' );
52 has 'nt' => ( is => 'rw', isa => 'NewType' );
56 my $obj = MyObject->new;
60 } qr/Attribute \(ar\) does not pass the type constraint because: ref: ARRAY/, '... got the right error message';
63 $foo->obj($foo); # Doh!
64 } qr/Attribute \(obj\) does not pass the type constraint because: Well it is an object/, '... got the right error message';
67 $foo->nt($foo); # scalar
68 } qr/Attribute \(nt\) does not pass the type constraint because: blessed/, '... got the right error message';