Resolve RT #56837 (reported by Sanko Robinson), based on his patch
[gitmo/Mouse.git] / lib / Mouse / PurePerl.pm
index 439217f..a5a7502 100644 (file)
@@ -280,7 +280,7 @@ sub new_object {
 }
 
 sub _initialize_object{
-    my($self, $object, $args, $ignore_triggers) = @_;
+    my($self, $object, $args, $is_cloning) = @_;
 
     my @triggers_queue;
 
@@ -300,7 +300,7 @@ sub _initialize_object{
         }
         else { # no init arg
             if ($attribute->has_default || $attribute->has_builder) {
-                if (!$attribute->is_lazy) {
+                if (!$attribute->is_lazy && !exists $object->{$slot}) {
                     my $default = $attribute->default;
                     my $builder = $attribute->builder;
                     my $value =   $builder                ? $object->$builder()
@@ -313,13 +313,13 @@ sub _initialize_object{
                         if ref($object->{$slot}) && $attribute->is_weak_ref;
                 }
             }
-            elsif($attribute->is_required) {
+            elsif(!$is_cloning && $attribute->is_required) {
                 $self->throw_error("Attribute (".$attribute->name.") is required");
             }
         }
     }
 
-    if(!$ignore_triggers){
+    if(@triggers_queue){
         foreach my $trigger_and_value(@triggers_queue){
             my($trigger, $value) = @{$trigger_and_value};
             $trigger->($object, $value);
@@ -617,6 +617,12 @@ sub compile_type_constraint{
     return;
 }
 
+sub check {
+    my $self = shift;
+    return $self->_compiled_type_constraint->(@_);
+}
+
+
 package Mouse::Object;
 
 sub BUILDARGS {
@@ -714,7 +720,7 @@ Mouse::PurePerl - A Mouse guts in pure Perl
 
 =head1 VERSION
 
-This document describes Mouse version 0.50_08
+This document describes Mouse version 0.55
 
 =head1 SEE ALSO