From: Christian Walde Date: Tue, 18 Dec 2012 16:11:24 +0000 (+0100) Subject: do not generate an accessor on an rw attr if reader and writer are defined, this... X-Git-Tag: v1.000008~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b1a9585fa5cad223ac68c95130c11b708b289874;p=gitmo%2FMoo.git do not generate an accessor on an rw attr if reader and writer are defined, this gives compatibility with Moose --- diff --git a/Changes b/Changes index f04f028..5a35527 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - Don't generate an accessor for rw attributes if reader+writer both set - Support builder => sub {} ala MooseX::AttributeShortcuts - Fix 'no Moo;' to preserve non-sub package variables - Switch to testing for Mouse::Util->can('find_meta') to avoid diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index 7a7bc26..c1ce749 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -24,7 +24,8 @@ sub generate_method { if ($is eq 'ro') { $spec->{reader} = $name unless exists $spec->{reader}; } elsif ($is eq 'rw') { - $spec->{accessor} = $name unless exists $spec->{accessor}; + $spec->{accessor} = $name unless exists $spec->{accessor} + or ( $spec->{reader} and $spec->{writer} ); } elsif ($is eq 'lazy') { $spec->{reader} = $name unless exists $spec->{reader}; $spec->{lazy} = 1; diff --git a/t/accessor-reader-writer.t b/t/accessor-reader-writer.t index eed47f9..04c0000 100644 --- a/t/accessor-reader-writer.t +++ b/t/accessor-reader-writer.t @@ -14,6 +14,8 @@ my @result; reader => 'get_one', writer => 'set_one', ); + + sub one {'sub'} } { @@ -33,6 +35,7 @@ my $bar = Bar->new(two => '...'); is( $foo->get_one, 'lol', 'reader works' ); $foo->set_one('rofl'); is( $foo->get_one, 'rofl', 'writer works' ); +is( $foo->one, 'sub', 'reader+writer = no accessor' ); ok( exception { $foo->get_one('blah') }, 'reader dies on write' );