Perl 在其他角色上实现要求';不行?
我的第一个角色是:Perl 在其他角色上实现要求';不行?,perl,moose,role,Perl,Moose,Role,我的第一个角色是: 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"
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";
我的第二个角色(实现第一个角色)是以下角色:
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";
我的基类如下所示:
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";
如果我不想启动我的程序,我会出现以下错误:
“acccack::RAccounting”需要实现方法“\u config”
通过“AccBack::Membership”访问
C:/草莓/perl/site/lib/Moose/Meta/Role/Application/ToCla
我不明白问题出在哪里。这是一样的事情
有人知道我误解了什么吗?这是一个已知的问题,有望在将来得到解决。同时,您应该能够通过添加如下stub方法来满足第二个角色中的要求:
sub _config;
has "_config" => (
isa => "Accounting::Config",
is => "ro",
lazy => 1,
default => sub { return Accounting::Config->new(); }
);
存根子节点将满足要求,但不会妨碍角色应用。只是一个猜测,但是如果将
with
语句放在顶部而不是底部,它是否有效?不,这将保证它不起作用;“has”和“with”都是正常的运行时函数调用。