X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FClassAttribute%2FRole%2FMeta%2FClass.pm;h=8ec293b4e75d3bacd1b8718eee51ecf757a73ddd;hb=ad109c62903c1bf4d05c93b57c059a1392e1d8b5;hp=e9ef9da69bc6c4d9694920e07ffd931838400781;hpb=aa6390299985f34313f45864361226b8e72ec272;p=gitmo%2FMooseX-ClassAttribute.git diff --git a/lib/MooseX/ClassAttribute/Role/Meta/Class.pm b/lib/MooseX/ClassAttribute/Role/Meta/Class.pm index e9ef9da..8ec293b 100644 --- a/lib/MooseX/ClassAttribute/Role/Meta/Class.pm +++ b/lib/MooseX/ClassAttribute/Role/Meta/Class.pm @@ -26,22 +26,25 @@ has _class_attribute_values => ( init_arg => undef, ); -sub add_class_attribute { +around add_class_attribute => sub { + my $orig = shift; my $self = shift; - - my $attr - = blessed $_[0] && $_[0]->isa('Class::MOP::Attribute') + my $attr = ( + blessed $_[0] && $_[0]->isa('Class::MOP::Attribute') ? $_[0] - : $self->_process_class_attribute(@_); + : $self->_process_class_attribute(@_) + ); - my $name = $attr->name(); + $self->$orig($attr); - $self->remove_class_attribute($name) - if $self->has_class_attribute($name); + return $attr; +}; - $attr->attach_to_class($self); +sub _post_add_class_attribute { + my $self = shift; + my $attr = shift; - $self->_add_class_attribute( $name => $attr ); + my $name = $attr->name(); my $e = do { local $@; @@ -53,8 +56,11 @@ sub add_class_attribute { $self->remove_attribute($name); die $e; } +} - return $attr; +sub _attach_class_attribute { + my ($self, $attribute) = @_; + $attribute->attach_to_class($self); } # It'd be nice if I didn't have to replicate this for class @@ -104,23 +110,18 @@ sub _process_inherited_class_attribute { return $inherited_attr->clone_and_inherit_options(%p); } -sub remove_class_attribute { +around remove_class_attribute => sub { + my $orig = shift; my $self = shift; - my $name = shift; - - ( defined $name && $name ) - || confess 'You must provide an attribute name'; - my $removed_attr = $self->get_class_attribute($name); - return unless $removed_attr; - - $self->_remove_class_attribute($name); + my $removed_attr = $self->$orig(@_) + or return; $removed_attr->remove_accessors(); $removed_attr->detach_from_class(); return $removed_attr; -} +}; sub get_all_class_attributes { my $self = shift;