next if $self->is_method_excluded($method_name);
- my $orig_method_name = $method_name;
-
- if ($self->is_method_aliased($method_name)) {
- $method_name = $self->get_method_aliases->{$method_name};
- }
-
# it if it has one already
if ($class->has_method($method_name) &&
# and if they are not the same thing ...
$class->get_method($method_name)->body != $role->get_method($method_name)->body) {
next;
}
- else {
+ else {
+
# add it, although it could be overriden
$class->alias_method(
$method_name,
- $role->get_method($orig_method_name)
- );
+ $role->get_method($method_name)
+ );
}
+
+ if ($self->is_method_aliased($method_name)) {
+ my $aliased_method_name = $self->get_method_aliases->{$method_name};
+ # it if it has one already
+ if ($class->has_method($aliased_method_name) &&
+ # and if they are not the same thing ...
+ $class->get_method($aliased_method_name)->body != $role->get_method($method_name)->body) {
+ confess "Cannot create a method alias if a local method of the same name exists";
+ }
+ $class->alias_method(
+ $aliased_method_name,
+ $role->get_method($method_name)
+ );
+ }
}
# we must reset the cache here since
# we are just aliasing methods, otherwise
my ($self, $role1, $role2) = @_;
foreach my $method_name ($role1->get_method_list) {
- next if $self->is_method_excluded($method_name);
-
- my $orig_method_name = $method_name;
-
- if ($self->is_method_aliased($method_name)) {
- $method_name = $self->get_method_aliases->{$method_name};
- }
+ next if $self->is_method_excluded($method_name);
# it if it has one already
if ($role2->has_method($method_name) &&
# add it, although it could be overriden
$role2->alias_method(
$method_name,
- $role1->get_method($orig_method_name)
+ $role1->get_method($method_name)
);
+
}
+
+ if ($self->is_method_aliased($method_name)) {
+ my $aliased_method_name = $self->get_method_aliases->{$method_name};
+ # it if it has one already
+ if ($role2->has_method($aliased_method_name) &&
+ # and if they are not the same thing ...
+ $role2->get_method($aliased_method_name)->body != $role1->get_method($method_name)->body) {
+ confess "Cannot create a method alias if a local method of the same name exists";
+ }
+ $role2->alias_method(
+ $aliased_method_name,
+ $role1->get_method($method_name)
+ );
+ }
}
}
use warnings;
use metaclass;
-use overload '""' => sub { shift->name }, # stringify to tc name
- fallback => 1;
+#use overload '""' => sub { shift->name }, # stringify to tc name
+# fallback => 1;
use Sub::Name 'subname';
use Carp 'confess';
::lives_ok {
with 'My::Role' => { alias => { bar => 'role_bar' } };
} '... this succeeds';
+
+ package My::Class::Failure;
+ use Moose;
+
+ ::throws_ok {
+ with 'My::Role' => { alias => { bar => 'role_bar' } };
+ } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds';
+
+ sub role_bar { 'FAIL' }
}
-ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
-ok(!My::Class->meta->has_method('bar'), '... but we dont get bar');
+ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz bar role_bar);
{
package My::OtherRole;
} '... this succeeds';
sub bar { 'My::OtherRole::bar' }
+
+ package My::OtherRole::Failure;
+ use Moose::Role;
+
+ ::throws_ok {
+ with 'My::Role' => { alias => { bar => 'role_bar' } };
+ } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds';
+
+ sub role_bar { 'FAIL' }
}
-ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo bar baz role_bar);
-ok(!My::OtherRole->meta->requires_method('bar'), '... and the &bar method is not required');
+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 required');
ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar method is not required');
ok(!defined(Number('Foo')), '... this is not a Num');
{
my $number_tc = Moose::Util::TypeConstraints::find_type_constraint('Number');
- is("$number_tc", 'Number', '... type constraint stringifies to name');
+ is($number_tc->name, 'Number', '... type constraint stringifies to name');
}
ok(String('Foo'), '... this is a Str');