add a test for the behavior in Reaction we were seeing ... and fix the oddness so...
Chris Prather [Sat, 29 Aug 2009 04:51:38 +0000 (00:51 -0400)]
lib/Moose/Meta/Attribute.pm
t/020_attributes/030_more_accessor_overriding.t [new file with mode: 0644]

index ac348be..f2a736f 100644 (file)
@@ -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 (file)
index 0000000..29fc376
--- /dev/null
@@ -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');