my ($self, $role1, $role2) = @_;
foreach my $method_name ($role1->get_method_list) {
+ unless ( $self->is_method_excluded($method_name) ) {
+ if ( $role2->has_method($method_name)
+ && $role2->get_method($method_name)->body
+ != $role1->get_method($method_name)->body ) {
+
+ # method conflicts between roles result in the method becoming
+ # a requirement
+ $role2->add_conflicting_method(
+ name => $method_name,
+ roles => [ $role1->name, $role2->name ],
+ );
+ }
+ else {
+ $role2->add_method(
+ $method_name,
+ $role1->get_method($method_name)
+ );
+ }
+ }
+
if ($self->is_method_aliased($method_name)) {
my $aliased_method_name = $self->get_method_aliases->{$method_name};
$role2->add_required_methods($method_name)
unless $self->is_method_excluded($method_name);
}
-
- next;
- }
-
- next if $self->is_method_excluded($method_name);
-
- if ($role2->has_method($method_name) &&
- $role2->get_method($method_name)->body != $role1->get_method($method_name)->body) {
- # method conflicts between roles result
- # in the method becoming a requirement
- $role2->add_conflicting_method(
- name => $method_name,
- roles => [$role1->name, $role2->name],
- );
- }
- else {
- $role2->add_method(
- $method_name,
- $role1->get_method($method_name)
- );
-
}
-
}
}
use strict;
use warnings;
-use Test::More tests => 38;
+use Test::More tests => 46;
use Test::Exception;
}
ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
-ok(!My::OtherRole->meta->requires_method('bar'), '... and the &bar method is not required');
+ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar method is not required');
{
}
ok(My::AliasingRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
-ok(My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is required');
+ok(!My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is not required');
{
package Foo::Role;
ok(My::Foo::AliasOnly->meta->has_method('foo'), 'we have a foo method');
ok(My::Foo::AliasOnly->meta->has_method('foo_foo'), '.. and the aliased foo_foo method');
+
+{
+ package Role::Foo;
+ use Moose::Role;
+
+ sub x1 {}
+ sub y1 {}
+}
+
+{
+ package Role::Bar;
+ use Moose::Role;
+
+ use Test::Exception;
+
+ lives_ok {
+ with 'Role::Foo' => {
+ -alias => { x1 => 'foo_x1' },
+ -excludes => ['y1'],
+ };
+ }
+ 'Compose Role::Foo into Role::Bar with alias and exclude';
+
+ sub x1 {}
+ sub y1 {}
+}
+
+{
+ my $bar = Role::Bar->meta;
+ ok( $bar->has_method($_), "has $_ method" )
+ for qw( x1 y1 foo_x1 );
+}
+
+{
+ package Role::Baz;
+ use Moose::Role;
+
+ use Test::Exception;
+
+ lives_ok {
+ with 'Role::Foo' => {
+ -alias => { x1 => 'foo_x1' },
+ -excludes => ['y1'],
+ };
+ }
+ 'Compose Role::Foo into Role::Baz with alias and exclude';
+}
+
+{
+ my $baz = Role::Baz->meta;
+ ok( $baz->has_method($_), "has $_ method" )
+ for qw( x1 foo_x1 );
+ ok( ! $baz->has_method('y1'), 'Role::Baz has no y1 method' );
+}