$accessor = ( keys %$accessor )[0] if ( ref($accessor) || '' ) eq 'HASH';
my $method = $self->associated_class->get_method($accessor);
+ if ( $method
+ && $method->isa('Class::MOP::Method::Accessor')
+ && $method->associated_attribute->name ne $self->name ) {
+
+ my $other_attr_name = $method->associated_attribute->name;
+ my $name = $self->name;
+
+ Carp::cluck(
+ "You are overwriting an accessor ($accessor) for the $other_attr_name attribute"
+ . " with a new accessor method for the $name attribute" );
+ }
+
if (
$method
&& !$method->isa('Class::MOP::Method::Accessor')
"You are overwriting a locally defined method ($accessor) with "
. "an accessor" );
}
+
if ( !$self->associated_class->has_method($accessor)
&& $self->associated_class->has_package_symbol( '&' . $accessor ) ) {
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+
+use Test::Requires {
+ 'Test::Output' => '0.01',
+};
+
+{
+ package Bar;
+ use Moose;
+
+ has has_attr => (
+ is => 'ro',
+ );
+
+ ::stderr_like{ has attr => (
+ is => 'ro',
+ predicate => 'has_attr',
+ )
+ }
+ qr/\QYou are overwriting an accessor (has_attr) for the has_attr attribute with a new accessor method for the attr attribute/,
+ 'overwriting an accessor for another attribute causes a warning';
+}
+
+done_testing;