From: Dave Rolsky Date: Mon, 1 Sep 2008 22:37:55 +0000 (+0000) Subject: Pass the invocant name to _inline_check_lazy for consistency (also X-Git-Tag: 0.57~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3da6fda87aeb051907be3b9c5e8f9d63fe454b00;p=gitmo%2FMoose.git Pass the invocant name to _inline_check_lazy for consistency (also makes my class attribute work saner) --- diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index a718871..8da980d 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -54,7 +54,7 @@ sub generate_accessor_method_inline { . $self->_inline_store($inv, $value_name) . "\n" . $self->_inline_trigger($inv, $value_name) . "\n" . ' }' . "\n" - . $self->_inline_check_lazy . "\n" + . $self->_inline_check_lazy($inv) . "\n" . $self->_inline_post_body(@_) . "\n" . 'return ' . $self->_inline_auto_deref($self->_inline_get($inv)) . "\n" . ' }'); @@ -90,7 +90,7 @@ sub generate_reader_method_inline { $self->_eval_code('sub {' . $self->_inline_pre_body(@_) . 'confess "Cannot assign a value to a read-only accessor" if @_ > 1;' - . $self->_inline_check_lazy + . $self->_inline_check_lazy($inv) . $self->_inline_post_body(@_) . 'return ' . $self->_inline_auto_deref( $slot_access ) . ';' . '}'); @@ -150,27 +150,27 @@ sub _inline_check_required { } sub _inline_check_lazy { - my $self = $_[0]; + my ($self, $instance) = @_; + my $attr = $self->associated_attribute; return '' unless $attr->is_lazy; - my $inv = '$_[0]'; - my $slot_access = $self->_inline_access($inv, $attr->name); + my $slot_access = $self->_inline_access($instance, $attr->name); - my $slot_exists = $self->_inline_has($inv, $attr->name); + my $slot_exists = $self->_inline_has($instance, $attr->name); my $code = 'unless (' . $slot_exists . ') {' . "\n"; if ($attr->has_type_constraint) { if ($attr->has_default || $attr->has_builder) { if ($attr->has_default) { - $code .= ' my $default = $attr->default(' . $inv . ');'."\n"; + $code .= ' my $default = $attr->default(' . $instance . ');'."\n"; } elsif ($attr->has_builder) { $code .= ' my $default;'."\n". - ' if(my $builder = '.$inv.'->can($attr->builder)){ '."\n". - ' $default = '.$inv.'->$builder; '. "\n } else {\n" . - ' confess(Scalar::Util::blessed('.$inv.')." does not support builder method '. + ' if(my $builder = '.$instance.'->can($attr->builder)){ '."\n". + ' $default = '.$instance.'->$builder; '. "\n } else {\n" . + ' confess(Scalar::Util::blessed('.$instance.')." does not support builder method '. '\'".$attr->builder."\' for attribute \'" . $attr->name . "\'");'. "\n }"; } $code .= ' $default = $type_constraint_obj->coerce($default);'."\n" if $attr->should_coerce; @@ -178,25 +178,25 @@ sub _inline_check_lazy { ' || confess "Attribute (" . $attr_name . ") does not pass the type constraint ("' . ' . $type_constraint_name . ") with " . (defined($default) ? overload::StrVal($default) : "undef");' . "\n"; - $code .= ' ' . $self->_inline_init_slot($attr, $inv, $slot_access, '$default') . "\n"; + $code .= ' ' . $self->_inline_init_slot($attr, $instance, $slot_access, '$default') . "\n"; } else { - $code .= ' ' . $self->_inline_init_slot($attr, $inv, $slot_access, 'undef') . "\n"; + $code .= ' ' . $self->_inline_init_slot($attr, $instance, $slot_access, 'undef') . "\n"; } } else { if ($attr->has_default) { - $code .= ' ' . $self->_inline_init_slot($attr, $inv, $slot_access, ('$attr->default(' . $inv . ')')) . "\n"; + $code .= ' ' . $self->_inline_init_slot($attr, $instance, $slot_access, ('$attr->default(' . $instance . ')')) . "\n"; } elsif ($attr->has_builder) { - $code .= ' if (my $builder = '.$inv.'->can($attr->builder)) { ' . "\n" - . ' ' . $self->_inline_init_slot($attr, $inv, $slot_access, ($inv . '->$builder')) + $code .= ' if (my $builder = '.$instance.'->can($attr->builder)) { ' . "\n" + . ' ' . $self->_inline_init_slot($attr, $instance, $slot_access, ($instance . '->$builder')) . "\n } else {\n" . - ' confess(Scalar::Util::blessed('.$inv.')." does not support builder method '. + ' confess(Scalar::Util::blessed('.$instance.')." does not support builder method '. '\'".$attr->builder."\' for attribute \'" . $attr->name . "\'");'. "\n }"; } else { - $code .= ' ' . $self->_inline_init_slot($attr, $inv, $slot_access, 'undef') . "\n"; + $code .= ' ' . $self->_inline_init_slot($attr, $instance, $slot_access, 'undef') . "\n"; } } $code .= "}\n";