use Scalar::Util 'blessed', 'weaken';
use overload ();
-our $VERSION = '0.79';
+our $VERSION = '0.83';
our $AUTHORITY = 'cpan:STEVAN';
use Moose::Meta::Method::Accessor;
$options->{accessor} ||= $name;
}
}
+ elsif ($options->{is} eq 'bare') {
+ # do nothing, but don't complain (later) about missing methods
+ }
else {
$class->throw_error("I do not understand this option (is => " . $options->{is} . ") on attribute ($name)", data => $options->{is});
}
my $self = shift;
$self->SUPER::install_accessors(@_);
$self->install_delegation if $self->has_handles;
+ unless (
+ @{ $self->associated_methods }
+ || ($self->_is_metadata || '') eq 'bare'
+ ) {
+ Carp::cluck(
+ 'Attribute (' . $self->name . ') has no associated methods'
+ . ' (did you mean to provide an "is" argument?)'
+ . "\n"
+ )
+ }
return;
}
my $method = $self->_make_delegation_method($handle, $method_to_call);
$self->associated_class->add_method($method->name, $method);
+ $self->associate_method($method);
}
}
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);
}
return map { $_ => $_ } (
$role_meta->get_method_list,
- $role_meta->get_required_method_list
+ map { $_->name } $role_meta->get_required_method_list,
);
}
}
$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,
);
}
=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
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
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.