实施要求其他角色不起作用?

时间:2011-08-25 16:35:17

标签: 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"            => (
    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 :: Membership'来   C:/草莓/的Perl /站点/ LIB /驼鹿/元/角色/应用/ ToCla

我不明白问题出在哪里。它与http://search.cpan.org/~doy/Moose-2.0203/lib/Moose/Cookbook/Roles/Recipe1.pod相同。

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

1 个答案:

答案 0 :(得分:5)

这是一个已知的问题,希望将来能够修复。在此期间,您应该能够通过添加这样的存根方法来满足第二个角色的要求:

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

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

相关问题