Subject: | applying a role twice produces class attribute conflicts |
See the attached test case.
Role1 and Role2 each define a different class attribute.
Applying them both to a class works.
Applying Role1 to Role2, and Role2 to the class, works.
Applying Role1 to Role2, and *both* to the class, fails.
The same test passes if we don't use class attributes, but normal attributes.
Subject: | role-role-class-composition.t |
#!perl
use strict;
use warnings;
use Test::More;
package Role1;{
use Moose::Role;
use MooseX::ClassAttribute;
class_has one => (is => 'rw');
};
package Role2_with1;{
use Moose::Role;
use MooseX::ClassAttribute;
with qw(Role1);
class_has two => (is => 'rw');
};
package Role2_without1;{
use Moose::Role;
use MooseX::ClassAttribute;
class_has two => (is => 'rw');
};
package main;
sub run_one_test {
my ($name,@roles) = @_;
my $code = qq{package $name;use Moose; with qw(@roles);1;};
ok(
eval($code),
'compiling the code should work',
);
for my $accessor (qw(one two)) {
ok(
$name->can($accessor),
"the class should have the ->$accessor accessor",
);
}
}
subtest 'each role applied once' => sub {
run_one_test(BothOnce=>qw(Role1 Role2_without1));
};
subtest 'role applied to role' => sub {
run_one_test(RoleRole=>qw(Role2_with1));
};
subtest 'role applied to role and class' => sub {
run_one_test(RoleRoleClass=>qw(Role1 Role2_with1));
};
done_testing;