From: Dave Rolsky Date: Wed, 20 Jan 2010 22:29:08 +0000 (-0600) Subject: more refactoring to prep for class attrs in roles X-Git-Tag: 0.11~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ad109c62903c1bf4d05c93b57c059a1392e1d8b5;p=gitmo%2FMooseX-ClassAttribute.git more refactoring to prep for class attrs in roles --- diff --git a/lib/MooseX/ClassAttribute/Role/Meta/Class.pm b/lib/MooseX/ClassAttribute/Role/Meta/Class.pm index e51d0a6..8ec293b 100644 --- a/lib/MooseX/ClassAttribute/Role/Meta/Class.pm +++ b/lib/MooseX/ClassAttribute/Role/Meta/Class.pm @@ -110,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; diff --git a/lib/MooseX/ClassAttribute/Role/Meta/Mixin/HasClassAttributes.pm b/lib/MooseX/ClassAttribute/Role/Meta/Mixin/HasClassAttributes.pm index 46b5a6e..1b7eb49 100644 --- a/lib/MooseX/ClassAttribute/Role/Meta/Mixin/HasClassAttributes.pm +++ b/lib/MooseX/ClassAttribute/Role/Meta/Mixin/HasClassAttributes.pm @@ -57,4 +57,19 @@ sub add_class_attribute { return $attribute; } +sub remove_class_attribute { + 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); + + return $removed_attr; +} + 1;