2

我的第一个角色是以下角色:

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' 由 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相同。

有人知道我误解了什么吗?

4

1 回答 1

5

这是一个已知问题,有望在未来得到解决。同时,您应该能够通过添加这样的存根方法来满足第二个角色的要求:

sub _config;
has "_config"            => (
    isa         => "Accounting::Config",
    is          => "ro",
    lazy        => 1,
    default     => sub { return Accounting::Config->new(); }
);

存根子将满足要求,但不会妨碍角色申请。

于 2011-08-25T17:10:47.403 回答