From: Jesse Luehrs Date: Thu, 25 Jun 2009 21:36:40 +0000 (-0500) Subject: warn if an accessor overrides a locally defined method X-Git-Tag: 0.84~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3b6e2290c5a401146915afb59a5dac2488259e1f;p=gitmo%2FMoose.git warn if an accessor overrides a locally defined method --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 81bdb2c..d98c6d8 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -553,6 +553,20 @@ sub install_accessors { return; } +sub _process_accessors { + my $self = shift; + my ($type, $accessor, $generate_as_inline_methods) = @_; + $accessor = (keys %$accessor)[0] if (ref($accessor)||'') eq 'HASH'; + if ($self->associated_class->has_method($accessor) + && !$self->associated_class->get_method($accessor)->isa('Class::MOP::Method::Accessor')) { + Carp::cluck( + "You cannot overwrite a locally defined method ($accessor) with " + . "an accessor" + ); + } + $self->SUPER::_process_accessors(@_); +} + sub remove_accessors { my $self = shift; $self->SUPER::remove_accessors(@_);