Tidy
gfx [Wed, 30 Sep 2009 11:16:46 +0000 (20:16 +0900)]
lib/Mouse/Meta/Class.pm
lib/Mouse/Meta/Method/Constructor.pm

index b5adde8..6abc7b2 100644 (file)
@@ -185,17 +185,12 @@ sub _initialize_instance{
                 unless ($attribute->is_lazy) {
                     my $default = $attribute->default;
                     my $builder = $attribute->builder;
-                    my $value = $attribute->has_builder
-                              ? $instance->$builder
-                              : ref($default) eq 'CODE'
-                                  ? $default->($instance)
-                                  : $default;
+                    my $value =   $builder                ? $instance->$builder()
+                                : ref($default) eq 'CODE' ? $instance->$default()
+                                :                           $default;
 
-                    $value = $attribute->coerce_constraint($value)
-                        if $attribute->should_coerce;
-                    $attribute->verify_against_type_constraint($value);
-
-                    $instance->{$key} = $value;
+                    # XXX: we cannot use $attribute->set_value() because it invokes triggers.
+                    $instance->{$key} = $attribute->_coerce_and_verify($value, $instance);;
 
                     weaken($instance->{$key})
                         if ref($instance->{$key}) && $attribute->is_weak_ref;
index f956fa2..f957750 100644 (file)
@@ -12,8 +12,8 @@ sub generate_constructor_method_inline {
     my $buildargs     = $class->_generate_BUILDARGS($metaclass);
     my $processattrs  = $class->_generate_processattrs($metaclass, \@attrs);
 
-    my @compiled_constraints = map { $_->_compiled_type_constraint }
-                               map { $_->{type_constraint} ? $_->{type_constraint} : () } @attrs;
+    my @compiled_constraints = map { $_ ? $_->_compiled_type_constraint : undef }
+                               map { $_->type_constraint } @attrs;
 
     my $code = sprintf("#line %d %s\n", __LINE__, __FILE__).<<"...";
     sub {