Use compute_all_applicable_attributes instead of get_attribute_map in the constructor...
[gitmo/Mouse.git] / lib / Mouse / Object.pm
index 70ad475..2138adf 100644 (file)
@@ -9,10 +9,21 @@ use Carp 'confess';
 
 sub new {
     my $class = shift;
-    my %args  = @_;
+    my %args;
+    if (scalar @_ == 1) {
+        if (defined $_[0]) {
+            (ref($_[0]) eq 'HASH')
+                || confess "Single parameters to new() must be a HASH ref";
+            %args = %{$_[0]};
+        }
+    }
+    else {
+        %args = @_;
+    }
+
     my $instance = bless {}, $class;
 
-    for my $attribute (values %{ $class->meta->get_attribute_map }) {
+    for my $attribute ($class->meta->compute_all_applicable_attributes) {
         my $from = $attribute->init_arg;
         my $key  = $attribute->name;
         my $default;
@@ -74,7 +85,7 @@ sub BUILDALL {
 
     no strict 'refs';
 
-    for my $class ($self->meta->linearized_isa) {
+    for my $class (reverse $self->meta->linearized_isa) {
         my $code = *{ $class . '::BUILD' }{CODE}
             or next;
         $code->($self, @_);