X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FAttribute.pm;h=bf599be97fbd4a40276809a89e78d5642692e1c9;hb=2de18801c55ae2cfac72d6697e797f3875286d83;hp=beb546bcdb1f6a47c63c122f4c31422d65de6006;hpb=246bbeef5959385671be705c87715042b049d41d;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index beb546b..bf599be 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -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, C, or C 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 for a read-write attribute, then you will have a C with the same name as the attribute, and a C 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 @@ -924,6 +938,11 @@ for an example. This method overrides the parent to also install delegation methods. +If, after installing all methods, the attribute object has no associated +methods, it throws an error unless C<< is => 'bare' >> was passed to the +attribute constructor. (Trying to add an attribute that has no associated +methods is almost always an error.) + =item B<< $attr->remove_accessors >> This method overrides the parent to also remove delegation methods.