加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – Can MooseX :: Method :: Signature可以与非Moose类一起

发布时间:2020-12-16 06:06:44 所属栏目:大数据 来源:网络整理
导读:我尝试了以下内容: package Foo;sub new { my ($type) = @_; return bless {},$type;}package Bar;use Moose;package Baz;use Moose;use MooseX::Method::Signatures;method exec1 (Foo $f,Bar $b) { ...;}method exec2 ($f where {$_-isa('Foo')},Bar $b)
我尝试了以下内容:

package Foo;
sub new {
    my ($type) = @_;
    return bless {},$type;
}

package Bar;
use Moose;

package Baz;
use Moose;
use MooseX::Method::Signatures;

method exec1 (Foo $f,Bar $b) {
    ...;
}
method exec2 ($f where {$_->isa('Foo')},Bar $b) {
    ...;
}

我发现exec2可以工作,但对于exec1,存在编译时错误.如果Foo是Mouse对象(这些是我无法更改的类),则会发生同样的错误.

'Foo' could not be parsed to a type constraint - maybe you need to pre-declare the type with class_type at C:/strawberry/perl/site/lib/Parse/Method/Signatures/TypeConstraint.pm line 74

但有没有办法可以使用exec1签名?

解决方法

在方法声明之前添加:

use Moose::Util::TypeConstraints;
BEGIN { class_type 'Foo'; }

错误很明显,对于MXMS无论如何;)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读