On role apply, apply all method modifiers
[gitmo/Mouse.git] / lib / Mouse / Object.pm
index 81cb9bf..1511d28 100644 (file)
@@ -2,8 +2,8 @@
 package Mouse::Object;
 use strict;
 use warnings;
-use MRO::Compat;
 
+use MRO::Compat;
 use Scalar::Util qw/blessed weaken/;
 use Carp 'confess';
 
@@ -24,13 +24,28 @@ sub new {
                 $attribute->trigger->{before}->($instance, $args->{$from}, $attribute);
             }
 
-            $attribute->verify_type_constraint($args->{$from})
-                if $attribute->has_type_constraint;
+            if ($attribute->has_trigger && $attribute->trigger->{around}) {
+                $attribute->trigger->{around}->(sub {
+                    $args->{$from} = $_[1];
+
+                    $attribute->verify_type_constraint($args->{$from})
+                        if $attribute->has_type_constraint;
 
-            $instance->{$key} = $args->{$from};
+                    $instance->{$key} = $args->{$from};
 
-            weaken($instance->{$key})
-                if ref($instance->{$key}) && $attribute->is_weak_ref;
+                    weaken($instance->{$key})
+                        if ref($instance->{$key}) && $attribute->is_weak_ref;
+                }, $instance, $args->{$from}, $attribute);
+            }
+            else {
+                $attribute->verify_type_constraint($args->{$from})
+                    if $attribute->has_type_constraint;
+
+                $instance->{$key} = $args->{$from};
+
+                weaken($instance->{$key})
+                    if ref($instance->{$key}) && $attribute->is_weak_ref;
+            }
 
             if ($attribute->has_trigger && $attribute->trigger->{after}) {
                 $attribute->trigger->{after}->($instance, $args->{$from}, $attribute);