X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FRole%2FComposite.pm;h=3dc28ad42d629d20c3bb3befca905ea269cc153a;hb=30350cb4d7b4345131ed638b2b30e7d1b7b1ef4c;hp=1a21b492ad67a245bcd9e5378639e9383ccecfa9;hpb=75b9541431131c67521bd1ec75df80c9707bd719;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Role/Composite.pm b/lib/Moose/Meta/Role/Composite.pm index 1a21b49..3dc28ad 100644 --- a/lib/Moose/Meta/Role/Composite.pm +++ b/lib/Moose/Meta/Role/Composite.pm @@ -4,10 +4,9 @@ use strict; use warnings; use metaclass; -use Carp 'confess'; use Scalar::Util 'blessed'; -our $VERSION = '0.55_01'; +our $VERSION = '0.65'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -35,7 +34,7 @@ sub new { my ($class, %params) = @_; # the roles param is required ... ($_->isa('Moose::Meta::Role')) - || confess "The list of roles must be instances of Moose::Meta::Role, not $_" + || Moose->throw_error("The list of roles must be instances of Moose::Meta::Role, not $_") foreach @{$params{roles}}; # and the name is created from the # roles if one has not been provided @@ -43,23 +42,29 @@ sub new { $class->_new(\%params); } -# NOTE: -# we need to override this cause -# we dont have that package I was -# talking about above. -# - SL -sub alias_method { +# This is largely a cope of what's in Moose::Meta::Role (itself +# largely a copy of Class::MOP::Class). However, we can't actually +# call add_package_symbol, because there's no package to which which +# add the symbol. +sub add_method { my ($self, $method_name, $method) = @_; (defined $method_name && $method_name) - || confess "You must define a method name"; - - # make sure to bless the - # method if nessecary - $method = $self->method_metaclass->wrap( - $method, - package_name => $self->name, - name => $method_name - ) if !blessed($method); + || Moose->throw_error("You must define a method name"); + + my $body; + if (blessed($method)) { + $body = $method->body; + if ($method->package_name ne $self->name) { + $method = $method->clone( + package_name => $self->name, + name => $method_name + ) if $method->can('clone'); + } + } + else { + $body = $method; + $method = $self->wrap_method_body( body => $body, name => $method_name ); + } $self->get_method_map->{$method_name} = $method; } @@ -88,7 +93,7 @@ Moose::Meta::Role::Composite - An object to represent the set of roles =item B -=item B +=item B =back