Subject: | Roles + 'requires attribute' doesn't work |
If a role says 'requires attribute', Moose will throw an exception, even
if the attribute is provided and the 'with' clause specifies the right
order.
See the following test script:
$ find . -type f | xargs perl -le'print "#### $_ ####" and print `cat
$_` for @ARGV' ;
#### ./y.pl ####
use strict;
use warnings;
use lib 'lib';
use Foo;
Foo->new;
#### ./lib/RoleB.pm ####
package RoleB;
use Moose::Role;
requires 'role_a';
1;
#### ./lib/Foo.pm ####
package Foo;
use Moose;
with 'RoleA', 'RoleB';
no Moose;
__PACKAGE__->meta->make_immutable;
1;
#### ./lib/RoleA.pm ####
package RoleA;
use Moose::Role;
has 'role_a' => ( is => 'rw' );
1;
$ perl y.pl
'RoleA|RoleB' requires the method 'role_a' to be implemented by 'Foo' at
/home/demo/perl/5.10/lib/site_perl/5.10.0/Moose/Meta/Role/Application.pm
line 59
Moose::Meta::Role::Application::apply('Moose::Meta::Role::Application::ToClass=HASH(0x89e4be0)',
'Moose::Meta::Role::Composite=HASH(0x89e4dc0)',
'Moose::Meta::Class=HASH(0x858c790)') called at
/home/demo/perl/5.10/lib/site_perl/5.10.0/Moose/Meta/Role/Application/ToClass.pm
line 18
Moose::Meta::Role::Application::ToClass::apply('Moose::Meta::Role::Application::ToClass=HASH(0x89e4be0)',
'Moose::Meta::Role::Composite=HASH(0x89e4dc0)',
'Moose::Meta::Class=HASH(0x858c790)') called at
/home/demo/perl/5.10/lib/site_perl/5.10.0/Moose/Meta/Role.pm line 441
Moose::Meta::Role::apply('Moose::Meta::Role::Composite=HASH(0x89e4dc0)',
'Moose::Meta::Class=HASH(0x858c790)') called at
/home/demo/perl/5.10/lib/site_perl/5.10.0/Moose/Util.pm line 119
Moose::Util::_apply_all_roles('Moose::Meta::Class=HASH(0x858c790)',
'CODE(0x88745e8)', 'RoleA', 'RoleB') called at
/home/demo/perl/5.10/lib/site_perl/5.10.0/Moose/Util.pm line 82
Moose::Util::apply_all_roles('Moose::Meta::Class=HASH(0x858c790)',
'RoleA', 'RoleB') called at
/home/demo/perl/5.10/lib/site_perl/5.10.0/Moose.pm line 65
Moose::with('Foo', 'RoleA', 'RoleB') called at
/home/demo/perl/5.10/lib/site_perl/5.10.0/Moose/Exporter.pm line 201
Moose::with('RoleA', 'RoleB') called at lib/Foo.pm line 3
require Foo.pm called at y.pl line 4
main::BEGIN() called at lib/Foo.pm line 0
eval {...} called at lib/Foo.pm line 0
Compilation failed in require at y.pl line 4.
BEGIN failed--compilation aborted at y.pl line 4.