From: Shawn M Moore Date: Wed, 16 Jul 2008 05:44:50 +0000 (+0000) Subject: Support before and after triggers in the constructor X-Git-Tag: 0.19~254 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d07212475afdc6ff3c61b9a63c1dd1dd326ff003;p=gitmo%2FMouse.git Support before and after triggers in the constructor --- diff --git a/lib/Mouse/Object.pm b/lib/Mouse/Object.pm index 8bf68d2..81cb9bf 100644 --- a/lib/Mouse/Object.pm +++ b/lib/Mouse/Object.pm @@ -20,6 +20,10 @@ sub new { my $default; if (defined($from) && exists($args->{$from})) { + if ($attribute->has_trigger && $attribute->trigger->{before}) { + $attribute->trigger->{before}->($instance, $args->{$from}, $attribute); + } + $attribute->verify_type_constraint($args->{$from}) if $attribute->has_type_constraint; @@ -28,8 +32,8 @@ sub new { weaken($instance->{$key}) if ref($instance->{$key}) && $attribute->is_weak_ref; - if ($attribute->has_trigger) { - $attribute->trigger->($instance, $args->{$from}, $attribute); + if ($attribute->has_trigger && $attribute->trigger->{after}) { + $attribute->trigger->{after}->($instance, $args->{$from}, $attribute); } } else {