From: Jesse Luehrs Date: Thu, 11 Nov 2010 03:29:45 +0000 (-0600) Subject: push a thin error throwing wrapper back here X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FClass-MOP.git;a=commitdiff_plain;h=753d754623cec6cb64d707fe5f993cef7d535788 push a thin error throwing wrapper back here --- diff --git a/lib/Class/MOP/Method/Accessor.pm b/lib/Class/MOP/Method/Accessor.pm index 5464f8f..c52a642 100644 --- a/lib/Class/MOP/Method/Accessor.pm +++ b/lib/Class/MOP/Method/Accessor.pm @@ -109,7 +109,7 @@ sub _generate_accessor_method_inline { return try { $self->_compile_code([ 'sub {', - 'if (@_ >= 2) {', + 'if (@_ > 1) {', $attr->_inline_set_value('$_[0]', '$_[1]'), '}', $attr->_inline_get_value('$_[0]'), @@ -139,8 +139,13 @@ sub _generate_reader_method_inline { 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]'), '}', ]); @@ -150,6 +155,11 @@ sub _generate_reader_method_inline { }; } +sub _inline_throw_error { + my $self = shift; + return 'confess ' . $_[0]; +} + sub _generate_writer_method { my $self = shift; my $attr = $self->associated_attribute;