Subject: | has with reader, writer, lazy and builder cannot create a write-only accessor |
The following code works in Moose and Mouse 0.52 but fails in 0.53.
package Foo;
use Mouse;
has history => (
reader => 'history',
writer => 'set_history',
builder => '_build_history',
lazy => 1,
);
__END__
syntax error at wo-accessor for history
(lib/Mouse/Meta/Method/Accessor.pm) line 5, near "}
elsif"
This is the code which is generated:
package Foo;
#line 1 "wo-accessor for history (lib/Mouse/Meta/Method/Accessor.pm)"
sub {
if(@_ < 2){ Carp::confess("Not enough arguments for the writer of
history") }{
return $_[0]->{q{history}} = $_[1];
}
elsif(!exists $_[0]->{q{history}}){
$_[0]->{q{history}} = $_[0]->$builder();
}
return $_[0]->{q{history}};
}
If you tidy that up it becomes clear:
package Foo;
#line 1 "wo-accessor for history (lib/Mouse/Meta/Method/Accessor.pm)"
sub {
if(@_ < 2){ Carp::confess("Not enough arguments for the writer of
history") }
{
return $_[0]->{q{history}} = $_[1];
}
elsif(!exists $_[0]->{q{history}}){
$_[0]->{q{history}} = $_[0]->$builder();
}
return $_[0]->{q{history}};
}
I think it's incorrect for the builder code to exist in the wo-accessor.