X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP%2FAttribute.pm;h=f8cfe644473e99d9dddd5f2bf8d7505508d3794d;hb=839ea97307cde7e936bff72d3f76d6213b9883a9;hp=fad8bda5ac11863b84e63c7e55d3282e67250fe0;hpb=291073fce8bb70dc65cb858786402a20b575cc97;p=gitmo%2FClass-MOP.git diff --git a/lib/Class/MOP/Attribute.pm b/lib/Class/MOP/Attribute.pm index fad8bda..f8cfe64 100644 --- a/lib/Class/MOP/Attribute.pm +++ b/lib/Class/MOP/Attribute.pm @@ -7,7 +7,7 @@ use warnings; use Carp 'confess'; use Scalar::Util 'blessed', 'reftype', 'weaken'; -our $VERSION = '0.06'; +our $VERSION = '0.07'; sub meta { require Class::MOP::Class; @@ -61,21 +61,17 @@ sub clone { } sub initialize_instance_slot { - my ($self, $class, $instance, $params) = @_; - # 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 ($self, $class, $meta_instance, $params) = @_; 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) - if (!defined $val && $self->{default}) { - $val = $self->default($instance); + if (!defined $val && defined $self->{default}) { + $val = $self->default($meta_instance->get_instance); } - $instance->{$self->{name}} = $val; + $meta_instance->add_slot($self->name, $val); } # NOTE: