X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FAttribute.pm;h=193e865e60c5020ec7fbc5fdde9622843ffd2faf;hb=eaf5a43ef108f6a9dce74c84afc25a892cffdfb1;hp=48a8f1778273d17c766c5428fd2c884c4c46a8e4;hpb=9340e346153b8eb4864763575c4bc77bed27d3dd;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 48a8f17..193e865 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -7,7 +7,7 @@ use warnings; use Scalar::Util 'blessed', 'weaken'; use overload (); -our $VERSION = '0.84'; +our $VERSION = '0.90'; our $AUTHORITY = 'cpan:STEVAN'; use Moose::Meta::Method::Accessor; @@ -40,6 +40,7 @@ __PACKAGE__->meta->add_attribute('trigger' => ( )); __PACKAGE__->meta->add_attribute('handles' => ( reader => 'handles', + writer => '_set_handles', predicate => 'has_handles', )); __PACKAGE__->meta->add_attribute('documentation' => ( @@ -163,7 +164,7 @@ my @legal_options_for_inheritance = qw( documentation lazy handles builder type_constraint definition_context - lazy_build + lazy_build weak_ref ); sub legal_options_for_inheritance { @legal_options_for_inheritance } @@ -495,6 +496,11 @@ sub set_value { my $meta_instance = Class::MOP::Class->initialize(blessed($instance)) ->get_meta_instance; + my @old; + if ( $self->has_trigger && $self->has_value($instance) ) { + @old = $self->get_value($instance, 'for trigger'); + } + $meta_instance->set_slot_value($instance, $attr_name, $value); if (ref $value && $self->is_weak_ref) { @@ -502,12 +508,12 @@ sub set_value { } if ($self->has_trigger) { - $self->trigger->($instance, $value); + $self->trigger->($instance, $value, @old); } } sub get_value { - my ($self, $instance) = @_; + my ($self, $instance, $for_trigger) = @_; if ($self->is_lazy) { unless ($self->has_value($instance)) { @@ -524,7 +530,7 @@ sub get_value { } } - if ($self->should_auto_deref) { + if ( $self->should_auto_deref && ! $for_trigger ) { my $type_constraint = $self->type_constraint; @@ -585,7 +591,7 @@ sub _process_accessors { && (!$self->definition_context || $method->package_name eq $self->definition_context->{package})) { Carp::cluck( - "You cannot overwrite a locally defined method ($accessor) with " + "You are overwriting a locally defined method ($accessor) with " . "an accessor" ); } @@ -681,10 +687,11 @@ sub _canonicalize_handles { (blessed $role_meta && $role_meta->isa('Moose::Meta::Role')) || $self->throw_error("Unable to canonicalize the 'handles' option with $handles because its metaclass is not a Moose::Meta::Role", data => $handles); - return map { $_ => $_ } ( + return map { $_ => $_ } + grep { $_ ne 'meta' } ( $role_meta->get_method_list, map { $_->name } $role_meta->get_required_method_list, - ); + ); } } @@ -730,11 +737,17 @@ sub _make_delegation_method { $method_body = $method_to_call if 'CODE' eq ref($method_to_call); + my @curried_arguments; + + ($method_to_call, @curried_arguments) = @$method_to_call + if 'ARRAY' eq ref($method_to_call); + return $self->delegation_metaclass->new( name => $handle_name, package_name => $self->associated_class->name, attribute => $self, delegate_to_method => $method_to_call, + curried_arguments => \@curried_arguments, ); }