Implement requires on other Role doesn't work?
My first Role is the following one:
package AccBack::RTransaction;
use strict;
use warnings;
use Moose::Role;
use MooseX::Method::Signatures;
requires "_log";
requires "_config";
My second Role, which implement the first Role, is the following one:
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 =&g开发者_运维问答t; "setFibu",
reader => "getFibu",
default => undef,
);
with "AccBack::RTransaction";
My base class is the following one:
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";
If I wan't to start my program, I get this error:
'AccBack::RAccounting' requires the method '_config' to be implemented by 'AccBack::Membership' at C:/strawberry/perl/site/lib/Moose/Meta/Role/Application/ToCla
I don't understand where the problem is. It is the same things as http://search.cpan.org/~doy/Moose-2.0203/lib/Moose/Cookbook/Roles/Recipe1.pod.
Does anybody have an idea about what I've misunderstand?
This is a known problem that will hopefully be fixed in the future. In the meantime, you should be able to satisfy the requirement in the second role by adding a stub method like this:
sub _config;
has "_config" => (
isa => "Accounting::Config",
is => "ro",
lazy => 1,
default => sub { return Accounting::Config->new(); }
);
The stub sub will fulfill the requirement, but will not get in the way of role application.
精彩评论