Some tests for before/after triggers in Mouse
[gitmo/Mouse.git] / lib / Mouse / Object.pm
index 04ad0ef..81cb9bf 100644 (file)
@@ -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 {
@@ -90,9 +94,9 @@ sub BUILDALL {
     # short circuit
     return unless $self->can('BUILD');
 
-    no strict 'refs';
-
     for my $class (reverse $self->meta->linearized_isa) {
+        no strict 'refs';
+        no warnings 'once';
         my $code = *{ $class . '::BUILD' }{CODE}
             or next;
         $code->($self, @_);