我意识到这可能是我对perl或Moose某些部分的基本误解,但我似乎无法从default
方法返回ArrayRef:
has '_directories' => (
is => 'ro',
isa => 'ArrayRef[Str]',
lazy => 1,
init_arg => undef,
default => method {return File::Spec->splitdir($self->relativeDirectory)});
给出:
Attribute (_directories) does not pass the type constraint because:
Validation failed for 'ArrayRef[Str]' with value 3
如何解决这个问题?
答案 0 :(得分:6)
splitdir
返回列表,而不是arrayref。您可以使用[]
构造函数从列表构造arrayref:
default => method {return [ File::Spec->splitdir($self->relativeDirectory) ] },