我尝试了以下内容:
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) {
...;
}
Run Code Online (Sandbox Code Playgroud)
我发现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
Run Code Online (Sandbox Code Playgroud)
但有没有办法可以使用exec1签名?
小智 5
在方法声明之前添加:
use Moose::Util::TypeConstraints;
BEGIN { class_type 'Foo'; }
Run Code Online (Sandbox Code Playgroud)
错误很明显,对于MXMS无论如何;)
| 归档时间: |
|
| 查看次数: |
153 次 |
| 最近记录: |