From: Fuji, Goro Date: Tue, 5 Oct 2010 15:11:59 +0000 (+0900) Subject: Resolve RT #61906, reported by Syohei Yoshida. X-Git-Tag: 0.80~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0464d337aad64f435f978dd97bc44af033545fac;p=gitmo%2FMouse.git Resolve RT #61906, reported by Syohei Yoshida. --- diff --git a/t/001_mouse/007-attributes.t b/t/001_mouse/007-attributes.t index e4afacb..8e89df2 100644 --- a/t/001_mouse/007-attributes.t +++ b/t/001_mouse/007-attributes.t @@ -29,6 +29,10 @@ do { reader => 'read_attr', writer => 'write_attr', ); + has 'attr2' => ( + is => 'rw', + accessor => 'rw_attr2', + ); }; with_immutable { ok(!Class->can('x'), "No accessor is injected if 'is' has no value"); @@ -66,6 +70,9 @@ with_immutable { is $object->write_attr("piyo"), "piyo"; is $object->rw_attr("yopi"), "yopi"; + can_ok $object, qw(rw_attr2); + ok !$object->can('attr2'), "doesn't have attr2"; + dies_ok { Class->rw_attr(); }; @@ -78,6 +85,6 @@ with_immutable { my @attrs = map { $_->name } sort { $a->insertion_order <=> $b->insertion_order } $object->meta->get_all_attributes; - is join(' ', @attrs), 'x y z attr', 'insertion_order'; + is join(' ', @attrs), 'x y z attr attr2', 'insertion_order'; } qw(Class); done_testing; diff --git a/t/900_mouse_bugs/012_RT61906.t b/t/900_mouse_bugs/012_RT61906.t new file mode 100644 index 0000000..163ce57 --- /dev/null +++ b/t/900_mouse_bugs/012_RT61906.t @@ -0,0 +1,35 @@ +#!perl +#https://rt.cpan.org/Ticket/Display.html?id=61906 +use strict; +use warnings; +use Test::More; + +package MouseObj; +use Mouse 0.78; + +has 'only_accessor' => ( + is => 'rw', + isa => 'Int', + accessor => 'only_accessor_accessor', +); + +has 'accesor_and_writer' => ( + is => 'rw', + isa => 'Int', + accessor => 'accesor_and_writer_accessor', + writer => 'accesor_and_writer_writer', +); + +has 'not_with_is' => ( + isa => 'Int', + accessor => 'not_with_is_accessor', +); + +package main; + +can_ok('MouseObj', 'only_accessor_accessor'); +can_ok('MouseObj', 'accesor_and_writer_accessor'); +can_ok('MouseObj', 'accesor_and_writer_writer'); +can_ok('MouseObj', 'not_with_is_accessor'); + +done_testing; diff --git a/xs-src/MouseAttribute.xs b/xs-src/MouseAttribute.xs index 3e4ef8d..5e20e92 100644 --- a/xs-src/MouseAttribute.xs +++ b/xs-src/MouseAttribute.xs @@ -339,7 +339,9 @@ CODE: else{ svp = hv_fetchs(args, "accessor", TRUE); } - sv_setsv(*svp, name); + if(!SvOK(*svp)) { + sv_setsv(*svp, name); + } } else if(strEQ(is, "bare")){ /* do nothing, but might complain later about missing methods */