From: Shawn M Moore Date: Sun, 2 Nov 2008 16:39:23 +0000 (+0000) Subject: Small fixes X-Git-Tag: 0.19~154 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7de13475544559b7f6ea43167a6314a61e59f9e2;p=gitmo%2FMouse.git Small fixes --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 5d91002..72570c8 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -68,16 +68,16 @@ sub generate_accessor { my $trigger = $attribute->trigger; my $self = '$_[0]'; - my $value = '$_[1]'; my $key = $attribute->inlined_name; my $accessor = "sub {\n"; if ($attribute->_is_metadata eq 'rw') { - $accessor .= 'if (scalar(@_) >= 2) { - '; + $accessor .= 'if (scalar(@_) >= 2) {' . "\n"; + + my $value = '$_[1]'; if ($constraint) { - $accessor .= 'local $_ = ' . $value . '; + $accessor .= 'local $_ = '.$value.'; 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"); @@ -89,6 +89,8 @@ sub generate_accessor { && !$trigger && !$attribute->should_auto_deref; + $accessor .= $self.'->{'.$key.'} = '.$value.';' . "\n"; + if ($attribute->is_weak_ref) { $accessor .= 'weaken('.$self.'->{'.$key.'}) if ref('.$self.'->{'.$key.'});' . "\n"; } @@ -118,12 +120,12 @@ sub generate_accessor { if ($attribute->type_constraint eq 'ArrayRef') { $accessor .= 'if (wantarray) { return @{ '.$self.'->{'.$key.'} || [] }; - }' . "\n"; + }'; } else { $accessor .= 'if (wantarray) { return %{ '.$self.'->{'.$key.'} || {} }; - }' . "\n"; + }'; } }