From: Jesse Luehrs Date: Sat, 19 Jun 2010 15:47:13 +0000 (-0500) Subject: warn if we try to overwrite a local function with an accessor X-Git-Tag: 1.09~48^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3968746e3249ebba86ee9caa5bc1cf423fba24bd;p=gitmo%2FMoose.git warn if we try to overwrite a local function with an accessor --- diff --git a/Changes b/Changes index 62405bf..b338d42 100644 --- a/Changes +++ b/Changes @@ -24,6 +24,11 @@ for, noteworthy changes. * Use Perl 5.10's new recursive regex features, if possible, for the type constraint parser (doy, nothingmuch). + [ENHANCEMENTS] + + * Attributes now warn if their accessors overwrite a locally defined function + (not just method) (doy). + [OTHER] * Bump our required perl version to 5.8.3, since earlier versions fail tests diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index dfdfbbe..1e84937 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -574,6 +574,13 @@ sub _process_accessors { . "an accessor" ); } + if (!$self->associated_class->has_method($accessor) + && $self->associated_class->has_package_symbol('&' . $accessor)) { + Carp::cluck( + "You are overwriting a locally defined function ($accessor) with " + . "an accessor" + ); + } $self->SUPER::_process_accessors(@_); } diff --git a/t/020_attributes/027_accessor_override_method.t b/t/020_attributes/027_accessor_override_method.t index 3c84cf7..b20ed3c 100644 --- a/t/020_attributes/027_accessor_override_method.t +++ b/t/020_attributes/027_accessor_override_method.t @@ -31,4 +31,7 @@ stderr_like(sub { $foo_meta->add_attribute(d => (clearer => 'clear_d')) }, stderr_like(sub { $foo_meta->add_attribute(e => (is => 'rw')) }, qr/^You are overwriting a locally defined method \(e\) with an accessor/, 'accessor overriding gives proper warning'); +stderr_like(sub { $foo_meta->add_attribute(has => (is => 'rw')) }, + qr/^You are overwriting a locally defined function \(has\) with an accessor/, 'function overriding gives proper warning'); + done_testing;