From: Stevan Little Date: Fri, 21 Apr 2006 21:09:29 +0000 (+0000) Subject: optimize X-Git-Tag: 0_26~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=37f36b2ad0bca80a86767b35c7267654b2d97ec7;p=gitmo%2FClass-MOP.git optimize --- diff --git a/lib/Class/MOP/Attribute.pm b/lib/Class/MOP/Attribute.pm index 6f70615..64542c2 100644 --- a/lib/Class/MOP/Attribute.pm +++ b/lib/Class/MOP/Attribute.pm @@ -68,9 +68,8 @@ sub initialize_instance_slot { $val = $params->{$init_arg} if exists $params->{$init_arg}; # if nothing was in the %params, we can use the # attribute's default value (if it has one) - if (!defined $val && $self->has_default) { - $val = $self->default($instance); - } + $val = $self->default($instance) + if !defined $val && $self->has_default; $instance->{$self->name} = $val; } diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 762c6a2..9c5cd84 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -475,21 +475,21 @@ sub add_attribute { || confess "Your attribute must be an instance of Class::MOP::Attribute (or a subclass)"; $attribute->attach_to_class($self); $attribute->install_accessors(); - $self->get_attribute_map->{$attribute->name} = $attribute; + $self->{'%:attributes'}->{$attribute->name} = $attribute; } sub has_attribute { my ($self, $attribute_name) = @_; (defined $attribute_name && $attribute_name) || confess "You must define an attribute name"; - exists $self->get_attribute_map->{$attribute_name} ? 1 : 0; + exists $self->{'%:attributes'}->{$attribute_name} ? 1 : 0; } sub get_attribute { my ($self, $attribute_name) = @_; (defined $attribute_name && $attribute_name) || confess "You must define an attribute name"; - return $self->get_attribute_map->{$attribute_name} + return $self->{'%:attributes'}->{$attribute_name} if $self->has_attribute($attribute_name); return; } @@ -508,7 +508,7 @@ sub remove_attribute { sub get_attribute_list { my $self = shift; - keys %{$self->get_attribute_map}; + keys %{$self->{'%:attributes'}}; } sub compute_all_applicable_attributes {