fixed bug, problem of coercer feature is moose compat
[gitmo/Mouse.git] / lib / Mouse / Object.pm
index 04ad0ef..a49d08c 100644 (file)
@@ -2,9 +2,8 @@
 package Mouse::Object;
 use strict;
 use warnings;
-use MRO::Compat;
 
-use Scalar::Util qw/blessed weaken/;
+use Mouse::Util qw/weaken/;
 use Carp 'confess';
 
 sub new {
@@ -20,6 +19,8 @@ sub new {
         my $default;
 
         if (defined($from) && exists($args->{$from})) {
+            $args->{$from} = $attribute->coerce_constraint($args->{$from})
+                if $attribute->should_coerce;
             $attribute->verify_type_constraint($args->{$from})
                 if $attribute->has_type_constraint;
 
@@ -43,6 +44,8 @@ sub new {
                                   ? $default->()
                                   : $default;
 
+                    $value = $attribute->coerce_constraint($value)
+                        if $attribute->should_coerce;
                     $attribute->verify_type_constraint($value)
                         if $attribute->has_type_constraint;
 
@@ -90,9 +93,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, @_);