more-tweaks
[gitmo/Moose.git] / lib / Moose / Meta / Class.pm
index 76fcbea..76f42f3 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 
 use Carp 'confess';
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 use base 'Class::MOP::Class';
 
@@ -21,9 +21,14 @@ sub construct_instance {
         # if nothing was in the %params, we can use the 
         # attribute's default value (if it has one)
         $val ||= $attr->default($instance) if $attr->has_default; 
-               if (defined $val && $attr->has_type_constraint) {
-                       (defined $attr->type_constraint->($val))
-                               || confess "Attribute (" . $attr->name . ") does not pass the type contraint";                  
+               if (defined $val) {
+                   if ($attr->has_type_constraint) {
+                   if ($attr->should_coerce && $attr->type_constraint->has_coercion) {
+                       $val = $attr->type_constraint->coercion->coerce($val);
+                   }   
+                (defined($attr->type_constraint->check($val))) 
+                    || confess "Attribute (" . $attr->name . ") does not pass the type contraint with '$val'";                 
+            }
                }
         $instance->{$attr->name} = $val;
     }
@@ -53,6 +58,8 @@ extensions.
 
 =item B<construct_instance>
 
+=item B<mixed_in>
+
 =back
 
 =head1 BUGS