Merge branch 'stable'
[gitmo/Class-MOP.git] / lib / Class / MOP / Method / Accessor.pm
index 5464f8f..01b3ecf 100644 (file)
@@ -8,7 +8,7 @@ use Carp         'confess';
 use Scalar::Util 'blessed', 'weaken';
 use Try::Tiny;
 
-our $VERSION   = '1.11';
+our $VERSION   = '1.12';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -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;