【发布时间】:2012-01-18 10:25:25
【问题描述】:
我尝试了以下方法:
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 签名?
【问题讨论】: