use Sub::Name 'subname';
use B 'svref_2object';
-our $VERSION = '0.19';
+our $VERSION = '0.20';
our $AUTHORITY = 'cpan:STEVAN';
use base 'Class::MOP::Module';
# make sure it is derived from the correct type though
($attribute->isa('Class::MOP::Attribute'))
|| confess "Your attribute must be an instance of Class::MOP::Attribute (or a subclass)";
+
+ # first we attach our new attribute
+ # because it might need certain information
+ # about the class which it is attached to
$attribute->attach_to_class($self);
+
+ # then we remove attributes of a conflicting
+ # name here so that we can properly detach
+ # the old attr object, and remove any
+ # accessors it would have generated
+ $self->remove_attribute($attribute->name)
+ if $self->has_attribute($attribute->name);
+
+ # then onto installing the new accessors
$attribute->install_accessors();
$self->get_attribute_map->{$attribute->name} = $attribute;
}
(defined $attribute_name && $attribute_name)
|| confess "You must define an attribute name";
return $self->get_attribute_map->{$attribute_name}
- if $self->has_attribute($attribute_name);
- return;
+ # NOTE:
+ # this will return undef anyway, so no need ...
+ # if $self->has_attribute($attribute_name);
+ #return;
}
sub remove_attribute {
=item B<get_method ($method_name)>
-This will return a CODE reference of the specified C<$method_name>,
-or return undef if that method does not exist.
+This will return a Class::MOP::Method instance related to the specified
+C<$method_name>, or return undef if that method does not exist.
+
+The Class::MOP::Method is codifiable, so you can use it like a normal
+CODE reference, see L<Class::MOP::Method> for more information.
=item B<find_method_by_name ($method_name>
methods which the C<$attribute_meta_object> has will be installed
into the class at this time.
+B<NOTE>
+If an attribute already exists for C<$attribute_name>, the old one
+will be removed (as well as removing all it's accessors), and then
+the new one added.
+
=item B<has_attribute ($attribute_name)>
Checks to see if this class has an attribute by the name of