From: Jesse Luehrs Date: Sat, 24 Oct 2009 18:42:38 +0000 (-0500) Subject: don't remove accessors we never installed X-Git-Tag: 0.93~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fe11f190958dd1e2bd888afb2f66fa81be9cfefd;hp=57a15379167087d6f566e1d2ef87052a7279ba50;p=gitmo%2FMoose.git don't remove accessors we never installed --- diff --git a/Changes b/Changes index 763fbd2..22a4aa8 100644 --- a/Changes +++ b/Changes @@ -23,6 +23,10 @@ for, noteworthy changes. main package. This applied to Moose and Moose::Role, among others. (nothingmuch) + * Moose::Meta::Attribute + - Don't remove attribute accessors we never installed, during + remove_accessors. (doy) + 0.92 Tue, Sep 22, 2009 * Moose::Util::TypeConstraints - added the match_on_type operator (Stevan) diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 55cb2c6..7490320 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -5,6 +5,7 @@ use strict; use warnings; use Scalar::Util 'blessed', 'weaken'; +use List::MoreUtils 'any'; use Try::Tiny; use overload (); @@ -657,6 +658,7 @@ sub remove_delegation { my %handles = $self->_canonicalize_handles; my $associated_class = $self->associated_class; foreach my $handle (keys %handles) { + next unless any { $handle eq $_ } $self->associated_methods; $self->associated_class->remove_method($handle); } } diff --git a/t/020_attributes/011_more_attr_delegation.t b/t/020_attributes/011_more_attr_delegation.t index 55a9212..34fdb45 100644 --- a/t/020_attributes/011_more_attr_delegation.t +++ b/t/020_attributes/011_more_attr_delegation.t @@ -191,9 +191,7 @@ do not fail at compile time. handles => sub { map { $_, $_ } $_[1]->get_all_method_names }, ); } "Can't override exisiting class method in delegate"; - { our $TODO; local $TODO = 'if add_attribute dies because a delegate would have overridden a local method, the rollback code removes the original method'; ::can_ok('Parent', 'parent_method_1'); - } ::lives_ok { has child_i => ( @@ -201,7 +199,7 @@ do not fail at compile time. is => "ro", default => sub { ChildI->new }, handles => sub { - map { $_, $_ } grep { !/^parent_method_1$/ } + map { $_, $_ } grep { !/^parent_method_1|meta$/ } $_[1]->get_all_method_names; }, ); @@ -260,6 +258,4 @@ can_ok( $p, "child_g_method_1" ); is( $p->child_g_method_1, "g1", "delegate to moose class without reader (child_g_method_1)" ); can_ok( $p, "child_i_method_1" ); -{ local $TODO = 'if add_attribute dies because a delegate would have overridden a local method, the rollback code removes the original method'; -lives_and { is( $p->parent_method_1, "parent_1", "delegate doesn't override existing method" ) }; -} +is( $p->parent_method_1, "parent_1", "delegate doesn't override existing method" );