在其他角色上实施要求不起作用?
我的第一个角色如下:
package AccBack::RTransaction;
use strict;
use warnings;
use Moose::Role;
use MooseX::Method::Signatures;
requires "_log";
requires "_config";
我的第二个角色实现了第一个角色,如下:
package AccBack::RAccounting;
use AccBack::RTransaction;
requires "_log";
has "_config" => (
isa => "Accounting::Config",
is => "ro",
lazy => 1,
default => sub { return Accounting::Config->new(); }
);
has "fibu" => (
isa => "Maybe[Accounting::Fibu]",
is => "rw",
writer => "setFibu",
reader => "getFibu",
default => undef,
);
with "AccBack::RTransaction";
我的基类如下:
package AccBack::Membership;
use AccBack::RAccounting;
has "_log" => (
isa => "Log::Log4perl::Logger",
is => "ro",
default => sub {
return Log::Log4perl->get_logger("AccBack::Membership");
}
);
has "mailMergeOption" => (
isa => "Maybe[HashRef]",
is => "rw",
writer => "setMailMergeOption",
reader => "getMailMergeOption",
default => undef,
);
# Roles
with "AccBack::RAccounting";
如果我不想启动我的程序,则会收到此错误:
“AccBack::RAccounting”需要实现“_config”方法 通过“AccBack::会员资格” C:/strawberry/perl/site/lib/Moose/Meta/Role/Application/ToCla
我不明白问题出在哪里。它与 http:// 相同search.cpan.org/~doy/Moose-2.0203/lib/Moose/Cookbook/Roles/Recipe1.pod。
有人知道我误解了什么吗?
My first Role is the following one:
package AccBack::RTransaction;
use strict;
use warnings;
use Moose::Role;
use MooseX::Method::Signatures;
requires "_log";
requires "_config";
My second Role, which implement the first Role, is the following one:
package AccBack::RAccounting;
use AccBack::RTransaction;
requires "_log";
has "_config" => (
isa => "Accounting::Config",
is => "ro",
lazy => 1,
default => sub { return Accounting::Config->new(); }
);
has "fibu" => (
isa => "Maybe[Accounting::Fibu]",
is => "rw",
writer => "setFibu",
reader => "getFibu",
default => undef,
);
with "AccBack::RTransaction";
My base class is the following one:
package AccBack::Membership;
use AccBack::RAccounting;
has "_log" => (
isa => "Log::Log4perl::Logger",
is => "ro",
default => sub {
return Log::Log4perl->get_logger("AccBack::Membership");
}
);
has "mailMergeOption" => (
isa => "Maybe[HashRef]",
is => "rw",
writer => "setMailMergeOption",
reader => "getMailMergeOption",
default => undef,
);
# Roles
with "AccBack::RAccounting";
If I wan't to start my program, I get this error:
'AccBack::RAccounting' requires the method '_config' to be implemented
by 'AccBack::Membership' at
C:/strawberry/perl/site/lib/Moose/Meta/Role/Application/ToCla
I don't understand where the problem is. It is the same things as http://search.cpan.org/~doy/Moose-2.0203/lib/Moose/Cookbook/Roles/Recipe1.pod.
Does anybody have an idea about what I've misunderstand?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个已知问题,有望在将来得到解决。同时,您应该能够通过添加如下的存根方法来满足第二个角色的要求:
存根子方法将满足要求,但不会妨碍角色应用。
This is a known problem that will hopefully be fixed in the future. In the meantime, you should be able to satisfy the requirement in the second role by adding a stub method like this:
The stub sub will fulfill the requirement, but will not get in the way of role application.