【发布时间】:2011-08-25 16:35:16
【问题描述】:
我的第一个角色如下:
package AccBack::RTransaction;
use strict;
use warnings;
use Moose::Role;
use MooseX::Method::Signatures;
requires "_log";
requires "_config";
我的第二个 Role 实现了第一个 Role,如下所示:
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::RAAccounting' 需要实现方法 '_config' 由“AccBack::Membership”在 C:/strawberry/perl/site/lib/Moose/Meta/Role/Application/ToCla
我不明白问题出在哪里。和http://search.cpan.org/~doy/Moose-2.0203/lib/Moose/Cookbook/Roles/Recipe1.pod是一样的。
有人知道我误解了什么吗?
【问题讨论】:
-
只是一个猜测,但如果将
with语句放在顶部而不是底部,它是否有效? -
不,那将保证它不起作用; 'has' 和 'with' 都是正常的运行时函数调用。