From: Jesse Luehrs Date: Thu, 11 Nov 2010 01:50:39 +0000 (-0600) Subject: add a hook in here for moose to override X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a0c6ecac8cae9e5aca1dc729e14630b85d8bfd34;p=gitmo%2FClass-MOP.git add a hook in here for moose to override --- diff --git a/lib/Class/MOP/Attribute.pm b/lib/Class/MOP/Attribute.pm index bbcf98b..26cd2fb 100644 --- a/lib/Class/MOP/Attribute.pm +++ b/lib/Class/MOP/Attribute.pm @@ -148,16 +148,25 @@ sub _set_initial_slot_value { return $meta_instance->set_slot_value($instance, $slot_name, $value) unless $self->has_initializer; - my $callback = sub { - $meta_instance->set_slot_value($instance, $slot_name, $_[0]); - }; - + my $callback = $self->_make_initializer_writer_callback( + $meta_instance, $instance, $slot_name + ); + my $initializer = $self->initializer; # most things will just want to set a value, so make it first arg $instance->$initializer($value, $callback, $self); } +sub _make_initializer_writer_callback { + my $self = shift; + my ($meta_instance, $instance, $slot_name) = @_; + + return sub { + $meta_instance->set_slot_value($instance, $slot_name, $_[0]); + }; +} + sub get_read_method { my $self = shift; my $reader = $self->reader || $self->accessor; diff --git a/t/014_attribute_introspection.t b/t/014_attribute_introspection.t index 57819e0..6a9bb21 100644 --- a/t/014_attribute_introspection.t +++ b/t/014_attribute_introspection.t @@ -22,6 +22,7 @@ use Class::MOP; initialize_instance_slot _set_initial_slot_value + _make_initializer_writer_callback name has_accessor accessor