sub initialize_instance_slot {
my ($self, $class, $instance, $params) = @_;
- my $init_arg = $self->init_arg();
+ # OPTIMIZATION NOTE:
+ # We break the attribute encapsulation here
+ # in order to save a number of method calls
+ # to $self and speed things up a bit
+ my $init_arg = $self->{init_arg};
# try to fetch the init arg from the %params ...
my $val;
$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)
- $val = $self->default($instance)
- if !defined $val && $self->has_default;
- $instance->{$self->name} = $val;
+ if (!defined $val && $self->{default}) {
+ $val = $self->default($instance);
+ }
+ $instance->{$self->{name}} = $val;
}
# NOTE:
|| confess "Your attribute must be an instance of Class::MOP::Attribute (or a subclass)";
$attribute->attach_to_class($self);
$attribute->install_accessors();
- $self->{'%:attributes'}->{$attribute->name} = $attribute;
+ $self->get_attribute_map->{$attribute->name} = $attribute;
}
sub has_attribute {
my ($self, $attribute_name) = @_;
(defined $attribute_name && $attribute_name)
|| confess "You must define an attribute name";
- exists $self->{'%:attributes'}->{$attribute_name} ? 1 : 0;
+ exists $self->get_attribute_map->{$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->{'%:attributes'}->{$attribute_name}
+ return $self->get_attribute_map->{$attribute_name}
if $self->has_attribute($attribute_name);
return;
}
sub get_attribute_list {
my $self = shift;
- keys %{$self->{'%:attributes'}};
+ keys %{$self->get_attribute_map};
}
sub compute_all_applicable_attributes {