From: Shawn M Moore Date: Sun, 2 Nov 2008 15:57:37 +0000 (+0000) Subject: Localize $_ only if we're checking a type constraint X-Git-Tag: 0.19~161 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ed1eec3957c7303860f79ff7f6117106a80f9d37;p=gitmo%2FMouse.git Localize $_ only if we're checking a type constraint --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 1588641..d918e3d 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -66,23 +66,24 @@ sub generate_accessor { if ($attribute->_is_metadata eq 'rw') { $accessor .= 'if (@_) { - local $_ = $_[0];'; + '; if ($constraint) { - $accessor .= 'unless ($constraint->()) { + $accessor .= 'local $_ = $_[0]; + unless ($constraint->()) { my $display = defined($_) ? overload::StrVal($_) : "undef"; Carp::confess("Attribute ($name) does not pass the type constraint because: Validation failed for \'$type\' failed with value $display"); }' } - $accessor .= '$self->{$key} = $_;'; + $accessor .= '$self->{$key} = $_[0];'; if ($attribute->is_weak_ref) { $accessor .= 'weaken($self->{$key}) if ref($self->{$key});'; } if ($trigger) { - $accessor .= '$trigger->($self, $_, $attribute);'; + $accessor .= '$trigger->($self, $_[0], $attribute);'; } $accessor .= '}';