X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FRole.pm;h=01689cc3df83eb6ce2cb8197b7ceecf0fa0d4c1a;hb=50bc108bca305ced4df63a569c9b5f3474f71914;hp=d872f7947ff92fa1e6cf157f628c9db4725b459f;hpb=c245d69b0b9984226cc876c0578b18e89b5cbf23;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index d872f79..01689cc 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -7,7 +7,7 @@ use metaclass; use Scalar::Util 'blessed'; -our $VERSION = '0.57'; +our $VERSION = '0.59'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -121,6 +121,8 @@ foreach my $action ( sub add_attribute { my $self = shift; my $name = shift; + (defined $name && $name) + || Moose->throw_error("You must provide a name for the attribute"); my $attr_desc; if (scalar @_ == 1 && ref($_[0]) eq 'HASH') { $attr_desc = $_[0]; @@ -371,15 +373,13 @@ sub has_method { sub wrap_method_body { my ( $self, %args ) = @_; - my $body = delete $args{body}; # delete is for compat - - ('CODE' eq ref($body)) + ('CODE' eq ref $args{body}) || Moose->throw_error("Your code block must be a CODE reference"); - $self->method_metaclass->wrap( $body => ( + $self->method_metaclass->wrap( package_name => $self->name, %args, - )); + ); } sub add_method { @@ -390,14 +390,10 @@ sub add_method { my $body; if (blessed($method)) { $body = $method->body; - if ($method->package_name ne $self->name && - $method->name ne $method_name) { - warn "Hello there, got something for you." - . " Method says " . $method->package_name . " " . $method->name - . " Class says " . $self->name . " " . $method_name; + if ($method->package_name ne $self->name) { $method = $method->clone( package_name => $self->name, - name => $method_name + name => $method_name ) if $method->can('clone'); } } @@ -427,18 +423,9 @@ sub get_method_list { } sub alias_method { - my ($self, $method_name, $method) = @_; - (defined $method_name && $method_name) - || Moose->throw_error("You must define a method name"); - - my $body = (blessed($method) ? $method->body : $method); - ('CODE' eq ref($body)) - || Moose->throw_error("Your code block must be a CODE reference"); + my $self = shift; - $self->add_package_symbol( - { sigil => '&', type => 'CODE', name => $method_name }, - $body - ); + $self->add_method(@_); } ## ------------------------------------------------------------------