X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FAttribute.pm;h=4bdb9f8167b0077ac8a323b9b883fc8c2d2d34f0;hb=cbdd0fa406d4f9d23a0d6a17891daf995e4c84c5;hp=1c46633cfb87db693f6d705dd801c7055df0aa52;hpb=4e757c98541b96d622e86b74d50d25ce183f7697;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 1c46633..4bdb9f8 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -76,17 +76,28 @@ sub generate_accessor { $accessor .= '$before->($self, $_, $attribute);'; } - if ($constraint) { - $accessor .= 'do { - 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") unless $constraint->(); - };' + if ($around) { + $accessor .= '$around->(sub { + my $self = shift; + $_ = $_[0]; + '; } - $accessor .= '$self->{$key} = $_;'; + if ($constraint) { + $accessor .= 'do { + 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") unless $constraint->(); + };' + } - if ($attribute->is_weak_ref) { - $accessor .= 'Scalar::Util::weaken($self->{$key}) if ref($self->{$key});'; + $accessor .= '$self->{$key} = $_;'; + + if ($attribute->is_weak_ref) { + $accessor .= 'Scalar::Util::weaken($self->{$key}) if ref($self->{$key});'; + } + + if ($around) { + $accessor .= '}, $self, $_, $attribute);'; } if ($after) {