X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FMethod%2FAccessor.pm;h=837eb1de76b775835c5c993afde33a091b860a69;hb=7a431e9c3e8c7ccf455d775c939ea85bd7d7dc30;hp=3a127860a0485797e9d6855b4e2f09341f2170e7;hpb=1c7518d411958aa1651b82bbc8238265c6248f75;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index 3a12786..837eb1d 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -4,7 +4,7 @@ package Moose::Meta::Method::Accessor; use strict; use warnings; -our $VERSION = '1.13'; +our $VERSION = '1.18'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -19,20 +19,8 @@ sub _error_thrower { sub _eval_code { my ( $self, $source ) = @_; - # NOTE: - # set up the environment - my $attr = $self->associated_attribute; - my $type_constraint_obj = $attr->type_constraint; - my $environment = { - '$attr' => \$attr, - '$meta' => \$self, - '$type_constraint_obj' => \$type_constraint_obj, - '$type_constraint' => \($type_constraint_obj - ? $type_constraint_obj->_compiled_type_constraint - : undef), - }; + my $environment = $self->_eval_environment; - #warn "code for " . $attr->name . " =>\n" . $source . "\n"; my ( $code, $e ) = $self->_compile_code( environment => $environment, code => $source ); $self->throw_error( @@ -43,9 +31,26 @@ sub _eval_code { return $code; } +sub _eval_environment { + my $self = shift; + + my $attr = $self->associated_attribute; + my $type_constraint_obj = $attr->type_constraint; + + return { + '$attr' => \$attr, + '$meta' => \$self, + '$type_constraint_obj' => \$type_constraint_obj, + '$type_constraint' => \( + $type_constraint_obj + ? $type_constraint_obj->_compiled_type_constraint + : undef + ), + }; +} + sub _generate_accessor_method_inline { my $self = $_[0]; - my $attr = $self->associated_attribute; my $inv = '$_[0]'; my $value_name = $self->_value_needs_copy ? '$val' : '$_[1]'; @@ -68,9 +73,7 @@ sub _generate_accessor_method_inline { sub _generate_writer_method_inline { my $self = $_[0]; - my $attr = $self->associated_attribute; my $inv = '$_[0]'; - my $slot_access = $self->_inline_get($inv); my $value_name = $self->_value_needs_copy ? '$val' : '$_[1]'; $self->_eval_code('sub { ' @@ -88,7 +91,6 @@ sub _generate_writer_method_inline { sub _generate_reader_method_inline { my $self = $_[0]; - my $attr = $self->associated_attribute; my $inv = '$_[0]'; my $slot_access = $self->_inline_get($inv); @@ -204,7 +206,7 @@ sub _inline_check_lazy { ';'. "\n }"; } $code .= $self->_inline_check_coercion('$default') . "\n"; - $code .= $self->_inline_check_constraint('$default') . "\n"; + $code .= $self->_inline_check_constraint('$default', 'lazy') . "\n"; $code .= ' ' . $self->_inline_init_slot($attr, $instance, '$default') . "\n"; } else { @@ -241,15 +243,9 @@ sub _inline_init_slot { } sub _inline_store { - my ($self, $instance, $value) = @_; - my $attr = $self->associated_attribute; + my ( $self, $instance, $value ) = @_; - my $mi = $attr->associated_class->get_meta_instance; - - 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_set( $instance, $value ); } sub _inline_get_old_value_for_trigger { @@ -258,12 +254,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"; } @@ -276,29 +269,14 @@ 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); -} - -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_get($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 {