Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 声明如何从属性默认方法返回ArrayRef?_Perl_Moose - Fatal编程技术网

Perl 声明如何从属性默认方法返回ArrayRef?

Perl 声明如何从属性默认方法返回ArrayRef?,perl,moose,Perl,Moose,我意识到这可能是我对perl或Moose某些部分的基本误解,但我似乎无法从默认方法返回ArrayRef: has '_directories' => ( is => 'ro', isa => 'ArrayRef[Str]', lazy => 1, init_arg => undef, default => method {return File::Spec->splitdir($self->relat

我意识到这可能是我对perl或Moose某些部分的基本误解,但我似乎无法从
默认方法返回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
如何排序?

返回列表,而不是arrayref。您可以使用
[]
构造函数从列表构造arrayref:

default => method {return [ File::Spec->splitdir($self->relativeDirectory) ] },