use Mouse;
use Mouse::Util::TypeConstraints;
type Baz => where { defined($_) && $_ eq 'Baz' };
+
coerce Baz => from 'ArrayRef', via { 'Baz' };
+
has 'bar' => ( is => 'rw', isa => 'Str | Baz | Undef', coerce => 1 );
}
eval {
Foo->new( bar => +{} );
};
-ok $@, 'not got an object';
+like($@, qr/^Attribute \(bar\) does not pass the type constraint because: Validation failed for 'Str\|Baz\|Undef' failed with value HASH\(\w+\)/, 'type constraint and coercion failed')
+ or diag "\$@='$@'";
eval {
isa_ok(Foo->new( bar => undef ), 'Foo');
eval {
$f->bar([]);
};
-ok !$@;
+ok !$@, $@;
is $f->bar, 'Baz', 'bar is baz (coerce from ArrayRef)';
eval {
{
package KLASS;
- sub new { bless {}, shift };
+ use Mouse;
}
{
package Funk;