From: Hans Dieter Pearcey Date: Fri, 26 Jun 2009 16:57:26 +0000 (-0400) Subject: make check_associated_methods better X-Git-Tag: 0.85~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=28af34248dee8c1212a4fe8874dc60fb275d6b33;p=gitmo%2FMoose.git make check_associated_methods better --- diff --git a/Changes b/Changes index 6884cb2..32f804a 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,12 @@ Also see Moose::Manual::Delta for more details of, and workarounds for, noteworthy changes. +0.85 + * Moose::Meta::Attribute + - The warning for 'no associated methods' is now split out into the + check_associated_methods method, so that extensions can safely call + 'after install_accessors => ...'. (hdp) + 0.84 Fri, Jun 26, 2009 * Moose::Role - has now sets definition_context for attributes defined in diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 25b94cb..b734854 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -557,6 +557,11 @@ sub install_accessors { my $self = shift; $self->SUPER::install_accessors(@_); $self->install_delegation if $self->has_handles; + return; +} + +sub check_associated_methods { + my $self = shift; unless ( @{ $self->associated_methods } || ($self->_is_metadata || '') eq 'bare' @@ -569,7 +574,6 @@ sub install_accessors { . "\n" ) } - return; } sub _process_accessors { @@ -827,7 +831,7 @@ 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. +metaclass. See L. =item * isa => $type @@ -1059,6 +1063,13 @@ Given a value, this method returns true if the value is valid for the attribute's type constraint. If the value is not valid, it throws an error. +=item B<< $attr->check_associated_methods >> + +This method makes sure that either an explicit C<< is => 'bare' >> was passed +to the attribute's constructor or that the attribute has at least one +associated method (reader, writer, delegation, etc.). Otherwise, it issues a +warning. + =item B<< $attr->handles >> This returns the value of the C option passed to the diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index 9059a02..0daeacb 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -243,11 +243,17 @@ sub superclasses { sub add_attribute { my $self = shift; - $self->SUPER::add_attribute( + my $attr = (blessed $_[0] && $_[0]->isa('Class::MOP::Attribute') ? $_[0] - : $self->_process_attribute(@_)) - ); + : $self->_process_attribute(@_)); + $self->SUPER::add_attribute($attr); + # it may be a Class::MOP::Attribute, theoretically, which doesn't have + # 'bare' and doesn't implement this method + if ($attr->can('check_associated_methods')) { + $attr->check_associated_methods; + } + return $attr; } sub add_override_method_modifier {