X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FMethod%2FAccessor.pm;h=38531bcbad278ebbe915c0f094afb918e429de38;hb=93ac97dd92e8c829816790b432a5638ad4585904;hp=ba46cbd4dc3f91d2b8607cfcca56013b4e425197;hpb=1ae8a0d7aaaa0627218d5026a013fb70113cce5a;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Method/Accessor.pm b/lib/Mouse/Meta/Method/Accessor.pm index ba46cbd..38531bc 100644 --- a/lib/Mouse/Meta/Method/Accessor.pm +++ b/lib/Mouse/Meta/Method/Accessor.pm @@ -27,36 +27,33 @@ sub generate_accessor_method_inline { if ($attribute->_is_metadata eq 'rw') { $accessor .= '#line ' . __LINE__ . ' "' . __FILE__ . "\"\n" . - 'if (@_ >= 2) {' . "\n"; + 'if (scalar(@_) >= 2) {' . "\n"; my $value = '$_[1]'; if ($constraint) { - $accessor .= 'my $val = '; if ($should_coerce) { $accessor .= "\n". '#line ' . __LINE__ . ' "' . __FILE__ . "\"\n" . - 'Mouse::Util::TypeConstraints->typecast_constraints("'.$attribute->associated_class->name.'", $attribute->{type_constraint}, '.$value.');'; - } else { - $accessor .= $value.';'; + 'my $val = Mouse::Util::TypeConstraints->typecast_constraints("'.$attribute->associated_class->name.'", $attribute->{type_constraint}, '.$value.');'; + $value = '$val'; } if ($compiled_type_constraint) { $accessor .= "\n". '#line ' . __LINE__ . ' "' . __FILE__ . "\"\n" . - 'unless ($compiled_type_constraint->($val)) { - $attribute->verify_type_constraint_error($name, $val, $attribute->{type_constraint}); + 'unless ($compiled_type_constraint->('.$value.')) { + $attribute->verify_type_constraint_error($name, '.$value.', $attribute->{type_constraint}); }' . "\n"; } else { $accessor .= "\n". '#line ' . __LINE__ . ' "' . __FILE__ . "\"\n" . - 'unless ($constraint->check($val)) { - $attribute->verify_type_constraint_error($name, $val, $attribute->{type_constraint}); + 'unless ($constraint->check('.$value.')) { + $attribute->verify_type_constraint_error($name, '.$value.', $attribute->{type_constraint}); }' . "\n"; } - $value = '$val'; } # if there's nothing left to do for the attribute we can return during @@ -91,7 +88,7 @@ sub generate_accessor_method_inline { } if ($should_deref) { - if (ref($constraint) && $constraint->name eq 'ArrayRef') { + if (ref($constraint) && $constraint->name =~ '^ArrayRef\b') { $accessor .= 'if (wantarray) { return @{ '.$self.'->{'.$key.'} || [] }; }';