From: Dave Rolsky Date: Sun, 26 Sep 2010 03:24:11 +0000 (-0500) Subject: Moved some inlining duties to Attribute class, which in turn delegates to meta-instance. X-Git-Tag: 1.15~75 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d67398abd3303d2fb8ed67d78313a202dec7283b;p=gitmo%2FMoose.git Moved some inlining duties to Attribute class, which in turn delegates to meta-instance. This makes it much easier for attributes from MX classes to change how inlining is done, without having to change the Accessor generators. --- diff --git a/lib/Moose.pm b/lib/Moose.pm index d0f1815..e80b523 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -14,7 +14,7 @@ use Carp 'confess'; use Moose::Deprecated; use Moose::Exporter; -use Class::MOP 1.05; +use Class::MOP 1.08; use Moose::Meta::Class; use Moose::Meta::TypeConstraint; diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 6eb4289..443b31a 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -577,6 +577,46 @@ sub remove_accessors { return; } +sub inline_get { + my $self = shift; + my ($instance) = @_; + + return $self->associated_class->get_meta_instance->inline_get_slot_value( + $instance, $self->slots ); +} + +sub inline_access { + my $self = shift; + my ($instance) = @_; + + return $self->associated_class->get_meta_instance->inline_slot_access( + $instance, $self->slots ); +} + +sub inline_has { + my $self = shift; + my ($instance) = @_; + + $self->associated_class->get_meta_instance->inline_is_slot_initialized( + $instance, $self->slots ); +} + +sub inline_store { + my $self = shift; + my ( $instance, $value ) = @_; + + my $mi = $self->associated_class->get_meta_instance; + + my $code + = $mi->inline_set_slot_value( $instance, $self->slots, $value ) . ";"; + $code + .= $mi->inline_weaken_slot_value( $instance, $self->slots, $value ) + . ";" + if $self->is_weak_ref; + + return $code; +} + sub install_delegation { my $self = shift; @@ -963,6 +1003,14 @@ methods is almost always an error.) This method overrides the parent to also remove delegation methods. +=item B<< $attr->inline_get >> + +=item B<< $attr->inline_access >> + +=item B<< $attr->inline_has >> + +=item B<< $attr->inline_store >> + =item B<< $attr->install_delegation >> This method adds its delegation methods to the attribute's associated diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index 84e7b13..2181e17 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -247,15 +247,9 @@ sub _inline_init_slot { } sub _inline_store { - my ($self, $instance, $value) = @_; - my $attr = $self->associated_attribute; - - my $mi = $attr->associated_class->get_meta_instance; + my ( $self, $instance, $value ) = @_; - my $code = $mi->inline_set_slot_value($instance, $attr->slots, $value) . ";"; - $code .= $mi->inline_weaken_slot_value($instance, $attr->slots, $value) . ";" - if $attr->is_weak_ref; - return $code; + return $self->associated_attribute->inline_store( $instance, $value ); } sub _inline_get_old_value_for_trigger { @@ -264,12 +258,9 @@ sub _inline_get_old_value_for_trigger { my $attr = $self->associated_attribute; return '' unless $attr->has_trigger; - my $mi = $attr->associated_class->get_meta_instance; - my $pred = $mi->inline_is_slot_initialized($instance, $attr->name); - return 'my @old = ' - . $pred . q{ ? } + . $self->_inline_has($instance) . q{ ? } . $self->_inline_get($instance) . q{ : ()} . ";\n"; } @@ -282,29 +273,20 @@ sub _inline_trigger { sub _inline_get { my ($self, $instance) = @_; - my $attr = $self->associated_attribute; - my $mi = $attr->associated_class->get_meta_instance; - - return $mi->inline_get_slot_value($instance, $attr->slots); + return $self->associated_attribute->inline_get($instance); } sub _inline_access { my ($self, $instance) = @_; - my $attr = $self->associated_attribute; - - my $mi = $attr->associated_class->get_meta_instance; - return $mi->inline_slot_access($instance, $attr->slots); + return $self->associated_attribute->inline_access($instance); } sub _inline_has { my ($self, $instance) = @_; - my $attr = $self->associated_attribute; - - my $mi = $attr->associated_class->get_meta_instance; - return $mi->inline_is_slot_initialized($instance, $attr->slots); + return $self->associated_attribute->inline_has($instance); } sub _inline_auto_deref { diff --git a/lib/Moose/Meta/Method/Accessor/Native/Collection.pm b/lib/Moose/Meta/Method/Accessor/Native/Collection.pm index b2f38dd..45b2340 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Collection.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Collection.pm @@ -86,14 +86,11 @@ sub _inline_get_old_value_for_trigger { my $attr = $self->associated_attribute; return '' unless $attr->has_trigger; - my $mi = $attr->associated_class->get_meta_instance; - my $pred = $mi->inline_is_slot_initialized( $instance, $attr->name ); - return - 'my @old = ' - . $pred . q{ ? } + 'my @old = ' + . $self->_inline_has($instance) . q{ ? } . $self->_inline_copy_old_value( $self->_inline_get($instance) ) - . " : ();\n"; + . ": ();\n"; } sub _eval_environment {