我的第一个角色是以下角色:
package AccBack::RTransaction;
use strict;
use warnings;
use Moose::Role;
use MooseX::Method::Signatures;
requires "_log";
requires "_config";
Run Code Online (Sandbox Code Playgroud)
我实现第一个角色的第二个角色是以下角色:
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";
Run Code Online (Sandbox Code Playgroud)
我的基类如下:
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";
Run Code Online (Sandbox Code Playgroud)
如果我不想启动我的程序,我会收到此错误:
'AccBack :: RAccounting'要求方法'_config'由C:/ strawberry/perl/site/lib/Moose/Meta/Role/Application/ToCla中的'AccBack :: Membership'实现
我不明白问题出在哪里.它与http://search.cpan.org/~doy/Moose-2.0203/lib/Moose/Cookbook/Roles/Recipe1.pod相同.
有没有人知道我误解了什么?
这是一个已知的问题,希望将来能够修复.在此期间,您应该能够通过添加如下所示的存根方法来满足第二个角色中的要求:
sub _config;
has "_config" => (
isa => "Accounting::Config",
is => "ro",
lazy => 1,
default => sub { return Accounting::Config->new(); }
);
Run Code Online (Sandbox Code Playgroud)
存根子将满足要求,但不会妨碍角色应用.