From: Chris Prather Date: Sat, 29 Aug 2009 04:51:38 +0000 (-0400) Subject: add a test for the behavior in Reaction we were seeing ... and fix the oddness so... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=81954f95bbe79890b4dbcbe6e1c567681f4fd71d;p=gitmo%2FMoose.git add a test for the behavior in Reaction we were seeing ... and fix the oddness so we have the same behavior as before --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index ac348be..f2a736f 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -591,10 +591,10 @@ sub _looks_like_overwriting_local_method { while ($method->isa('Class::MOP::Method::Wrapped')) { $method = $method->get_original_method; } - return 1 if !$method->isa('Class::MOP::Method::Accessor'); - return 0 if !$self->definition_context; + return 0 if $method->isa('Class::MOP::Method::Accessor'); + return 1 if !$self->definition_context; return 0 if $method->package_name ne $self->definition_context->{package}; - return 0; + return 1; } sub _process_accessors { @@ -604,7 +604,7 @@ sub _process_accessors { if ($self->_looks_like_overwriting_local_method($accessor)) { Carp::cluck( "You are overwriting a locally defined method ($accessor) with " - . "an accessor at line " .$self->definition_context->{line} + . "an accessor" ); } $self->SUPER::_process_accessors(@_); diff --git a/t/020_attributes/030_more_accessor_overriding.t b/t/020_attributes/030_more_accessor_overriding.t new file mode 100644 index 0000000..29fc376 --- /dev/null +++ b/t/020_attributes/030_more_accessor_overriding.t @@ -0,0 +1,33 @@ +#!/usr/bin/env perl +use strict; +use Test::More; + +BEGIN { + eval "use Test::Output;"; + plan skip_all => "Test::Output is required for this test" if $@; + plan tests => 1; +} + +{ + + package Role; + use Moose::Role; + + has value => ( + is => 'rw', + clearer => 'clear_value', + ); + + after clear_value => sub { }; +} +{ + + package Class; + use Moose; + + with 'Role'; + has '+value' => ( isa => q[Str] ); +} + +stderr_unlike(sub { Class->new; }, + qr/^You are overwriting a locally defined method \(get_a\) with an accessor/, 'reader overriding gives proper warning');