Deprecate compute_all_applicable_attributes() and get_attribute_map()
[gitmo/Mouse.git] / lib / Mouse / Meta / Class.pm
index b5adde8..cc3824d 100644 (file)
@@ -103,7 +103,7 @@ sub add_attribute {
             my $inherited_attr;
 
             foreach my $class($self->linearized_isa){
-                my $meta = Mouse::Meta::Module::get_metaclass_by_name($class) or next;
+                my $meta = Mouse::Util::get_metaclass_by_name($class) or next;
                 $inherited_attr = $meta->get_attribute($name) and last;
             }
 
@@ -131,16 +131,20 @@ sub add_attribute {
     return $attr;
 }
 
-sub compute_all_applicable_attributes { shift->get_all_attributes(@_) }
+sub compute_all_applicable_attributes {
+    Carp::cluck('compute_all_applicable_attributes() has been deprecated');
+    return shift->get_all_attributes(@_)
+}
+
 sub get_all_attributes {
     my $self = shift;
     my (@attr, %seen);
 
     for my $class ($self->linearized_isa) {
-        my $meta = $self->_metaclass_cache($class)
+        my $meta = Mouse::Util::get_metaclass_by_name($class)
             or next;
 
-        for my $name (keys %{ $meta->get_attribute_map }) {
+        for my $name ($meta->get_attribute_list) {
             next if $seen{$name}++;
             push @attr, $meta->get_attribute($name);
         }
@@ -185,17 +189,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;
-
-                    $value = $attribute->coerce_constraint($value)
-                        if $attribute->should_coerce;
-                    $attribute->verify_against_type_constraint($value);
+                    my $value =   $builder                ? $instance->$builder()
+                                : ref($default) eq 'CODE' ? $instance->$default()
+                                :                           $default;
 
-                    $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;
@@ -414,7 +413,7 @@ sub does_role {
         || $self->throw_error("You must supply a role name to look for");
 
     for my $class ($self->linearized_isa) {
-        my $meta = Mouse::Meta::Module::class_of($class);
+        my $meta = Mouse::Util::get_metaclass_by_name($class);
         next unless $meta && $meta->can('roles');
 
         for my $role (@{ $meta->roles }) {