return try {
$self->_compile_code([
'sub {',
- 'if (@_ >= 2) {',
+ 'if (@_ > 1) {',
$attr->_inline_set_value('$_[0]', '$_[1]'),
'}',
$attr->_inline_get_value('$_[0]'),
return try {
$self->_compile_code([
'sub {',
- 'confess "Cannot assign a value to a read-only accessor"',
- 'if @_ > 1;',
+ 'if (@_ > 1) {',
+ # XXX: this is a hack, but our error stuff is terrible
+ $self->_inline_throw_error(
+ '"Cannot assign a value to a read-only accessor"',
+ 'data => \@_'
+ ) . ';',
+ '}',
$attr->_inline_get_value('$_[0]'),
'}',
]);
};
}
+sub _inline_throw_error {
+ my $self = shift;
+ return 'confess ' . $_[0];
+}
+
sub _generate_writer_method {
my $self = shift;
my $attr = $self->associated_attribute;