好的,我做错了什么 - 穆斯无视我的强制行为:
package moo;
use Moose;
use Moose::Util::TypeConstraints;
subtype Bar => as 'ArrayRef[Num]';
coerce 'Bar' =>
from 'Num' => via { [ 10 ] }; # this doesn't seem to be getting called
has x => (
is => 'rw',
isa => 'Bar',
);
package main;
my $m1 = moo->new(x => [ 3 ]); # works
my $m2 = moo->new(x => 5); # doesn't work
答案 0 :(得分:7)
也许您在定义coerce => 1
属性时忘记了x
。
has x => ( is => 'rw', isa => 'Bar', coerce => 1 );
`