X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FRole%2FApplication%2FToRole.pm;h=ea582b7537aff62e5eb0d14c5e947202359b6edd;hb=6cde92b3c52848f42ac20937fce0aebc3c5e2325;hp=23cfd38c011ade945bc270777d656dee02cf088f;hpb=c45384475d0d20e835d5666615ce15b17e79ff4b;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Role/Application/ToRole.pm b/lib/Moose/Meta/Role/Application/ToRole.pm index 23cfd38..ea582b7 100644 --- a/lib/Moose/Meta/Role/Application/ToRole.pm +++ b/lib/Moose/Meta/Role/Application/ToRole.pm @@ -7,9 +7,8 @@ use metaclass; use Carp 'confess'; use Scalar::Util 'blessed'; -use Data::Dumper; - -our $VERSION = '0.01'; +our $VERSION = '0.55_04'; +$VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::Role::Application'; @@ -34,6 +33,9 @@ sub check_role_exclusions { sub check_required_methods { my ($self, $role1, $role2) = @_; foreach my $required_method_name ($role1->get_required_method_list) { + + next if $self->is_aliased_method($required_method_name); + $role2->add_required_methods($required_method_name) unless $role2->find_method_by_name($required_method_name); } @@ -66,7 +68,28 @@ sub apply_methods { my ($self, $role1, $role2) = @_; foreach my $method_name ($role1->get_method_list) { - next if $self->is_method_excluded($method_name); + next if $self->is_method_excluded($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) + ); + + if (!$role2->has_method($method_name)) { + $role2->add_required_methods($method_name); + } + + next; + } # it if it has one already if ($role2->has_method($method_name) && @@ -82,7 +105,9 @@ sub apply_methods { $method_name, $role1->get_method($method_name) ); + } + } } @@ -142,7 +167,7 @@ __END__ =head1 NAME -Moose::Meta::Role::Application::ToRole +Moose::Meta::Role::Application::ToRole - Compose a role into another role =head1 DESCRIPTION