add curried_arguments, usable from hashref handles
[gitmo/Moose.git] / lib / Moose / Meta / Attribute.pm
index 7f76bc3..bf599be 100644 (file)
@@ -541,14 +541,13 @@ sub install_accessors {
     $self->SUPER::install_accessors(@_);
     $self->install_delegation if $self->has_handles;
     unless (
-        # XXX handles should be in associated_methods
-        $self->has_handles
-        || @{ $self->associated_methods }
+        @{ $self->associated_methods }
         || ($self->_is_metadata || '') eq 'bare'
     ) {
-        $self->throw_error(
+        Carp::cluck(
             'Attribute (' . $self->name . ') has no associated methods'
             . ' (did you mean to provide an "is" argument?)'
+            . "\n"
         )
     }
     return;
@@ -595,6 +594,7 @@ sub install_delegation {
         my $method = $self->_make_delegation_method($handle, $method_to_call);
 
         $self->associated_class->add_method($method->name, $method);
+        $self->associate_method($method);
     }
 }
 
@@ -628,6 +628,9 @@ sub _canonicalize_handles {
         elsif ($handle_type eq 'CODE') {
             return $handles->($self, $self->_find_delegate_metaclass);
         }
+        elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::DuckType')) {
+            return map { $_ => $_ } @{ $handles->methods };
+        }
         else {
             $self->throw_error("Unable to canonicalize the 'handles' option with $handles", data => $handles);
         }
@@ -688,11 +691,17 @@ sub _make_delegation_method {
     $method_body = $method_to_call
         if 'CODE' eq ref($method_to_call);
 
+    my $curried_arguments = [];
+
+    ($method_to_call, $curried_arguments) = @$method_to_call
+        if 'ARRAY' eq ref($method_to_call);
+
     return $self->delegation_metaclass->new(
         name               => $handle_name,
         package_name       => $self->associated_class->name,
         attribute          => $self,
         delegate_to_method => $method_to_call,
+        curried_arguments  => $curried_arguments,
     );
 }
 
@@ -775,7 +784,7 @@ It adds the following options to the constructor:
 
 =over 8
 
-=item * is => 'ro' or 'rw'
+=item * is => 'ro', 'rw', 'bare'
 
 This provides a shorthand for specifying the C<reader>, C<writer>, or
 C<accessor> names. If the attribute is read-only ('ro') then it will
@@ -786,6 +795,11 @@ with the same name. If you provide an explicit C<writer> for a
 read-write attribute, then you will have a C<reader> with the same
 name as the attribute, and a C<writer> with the name you provided.
 
+Use 'bare' when you are deliberately not installing any methods
+(accessor, reader, etc.) associated with this attribute; otherwise,
+Moose will issue a deprecation warning when this attribute is added to a
+metaclass.
+
 =item * isa => $type
 
 This option accepts a type. The type can be a string, which should be