2

MooseX::Method::Signatures应该能够获取数组引用作为参数并将其用作方法中的普通数组,请参阅Method::Signatures 中的别名引用

以文档中的代码为例,我编写了:

package MethodSignatures;

use strict;
use warnings;

use Moose;
use MooseX::Method::Signatures;

method add_one(\@foo) {
    $_++ for @foo;
}

my @bar = ( 1, 2, 3 );
MethodSignatures->add_one(\@bar);    # @bar is now (2,3,4)

但是,它失败了:

')' expected whilst parsing signature near '@foo' in '\@foo' at d:/workspace/lib/tools/Perl/site/lib/MooseX/Method/Signatures/Meta/Method.pm line 199

这是因为我使用的是 Perl 5 吗?

4

1 回答 1

4

请注意MooseX::Method::SignaturesMethod::Signatures不同。前者没有提到\@foo原型允许的语法,所以它可能是失败的原因。

这两个模块都适用于 perl 5,所以这不应该是错误的原因。

于 2012-01-26T13:09:02.913 回答