From: Shawn M Moore Date: Wed, 16 Jul 2008 05:44:36 +0000 (+0000) Subject: Support before and after triggers in the setter X-Git-Tag: 0.19~255 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4e757c98541b96d622e86b74d50d25ce183f7697;p=gitmo%2FMouse.git Support before and after triggers in the setter --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 023ab4d..1c46633 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -56,11 +56,15 @@ sub generate_accessor { my $name = $attribute->name; my $key = $name; my $default = $attribute->default; - my $trigger = $attribute->trigger; my $type = $attribute->type_constraint; my $constraint = $attribute->find_type_constraint; my $builder = $attribute->builder; + my $trigger = $attribute->trigger; + my $before = $trigger->{before}; + my $after = $trigger->{after}; + my $around = $trigger->{around}; + my $accessor = 'sub { my $self = shift;'; @@ -68,6 +72,10 @@ sub generate_accessor { $accessor .= 'if (@_) { local $_ = $_[0];'; + if ($before) { + $accessor .= '$before->($self, $_, $attribute);'; + } + if ($constraint) { $accessor .= 'do { my $display = defined($_) ? overload::StrVal($_) : "undef"; @@ -81,8 +89,8 @@ sub generate_accessor { $accessor .= 'Scalar::Util::weaken($self->{$key}) if ref($self->{$key});'; } - if ($trigger) { - $accessor .= '$trigger->($self, $_, $attribute);'; + if ($after) { + $accessor .= '$after->($self, $_, $attribute);'; } $accessor .= '}';