Fix first to do what it's supposed to.
Just push curried args onto the front of @_ for simplicity.
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(
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;
$options{delegate_to_method} = lc( ( split /::/, $class)[-1] );
+ $options{definition_context} = $options{attribute}->definition_context;
+
my $self = $class->_new( \%options );
weaken( $self->{'attribute'} );
return;
}
+sub _eval_environment {
+ my $self = shift;
+
+ my $env = $self->SUPER::_eval_environment;
+
+ $env->{'@curried'} = $self->curried_arguments;
+
+ return $env;
+}
+
1;
use base 'Moose::Meta::Method::Accessor::Native';
-sub _value_needs_copy {
+sub _inline_curried_arguments {
my $self = shift;
- return @{ $self->curried_arguments };
-}
-
-sub _inline_copy_value {
- my $self = shift;
-
- return q{} unless $self->_value_needs_copy;
-
- my $curry = join ', ',
- map { looks_like_number($_) ? $_ : B::perlstring($_) }
- @{ $self->curried_arguments };
+ return q{} unless @{ $self->curried_arguments };
- return "my \@val = ( $curry, \@_ );";
+ return "\@_ = ( \@curried, \@_ );";
}
sub _inline_check_constraint {
$code .= "\n" . $self->_inline_pre_body(@_);
$code .= "\n" . 'my $self = shift;';
+ $code .= "\n" . $self->_inline_curried_arguments;
$code .= "\n" . $self->_inline_process_arguments;
$code
use strict;
use warnings;
+use List::Util ();
+
our $VERSION = '1.13';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
use base 'Moose::Meta::Method::Accessor::Native::Array::Reader';
+sub _inline_process_arguments {
+ return 'my $func = shift;';
+}
+
sub _return_value {
my $self = shift;
my $slot_access = shift;
- return "${slot_access}->[0]";
+ return "&List::Util::first( \$func, \@{ ${slot_access} } )";
}
1;
my $slot_access = $self->_inline_get($inv);
- my $value_name
- = $self->_value_needs_copy
- ? '@val'
- : '@_';
-
my $code = 'sub {';
$code .= "\n" . $self->_inline_pre_body(@_);
$code .= "\n" . $self->_inline_check_lazy($inv);
- $code .= "\n" . $self->_inline_copy_value;
+ $code .= "\n" . $self->_inline_curried_arguments;
$code
.= "\n"
. $self->_inline_throw_error(
q{"Cannot call push without any arguments"})
- . " unless $value_name;";
+ . " unless \@_;";
my $potential_new_val;
if ( $self->_constraint_must_be_checked ) {
- $code .= "\n" . "my \@new_val = ( \@{ $slot_access }, $value_name );";
+ $code .= "\n" . "my \@new_val = ( \@{ $slot_access }, \@_ );";
$potential_new_val = '\\@new_val';
}
else {
- $potential_new_val = "[ \@{ $slot_access }, $value_name ];";
+ $potential_new_val = "[ \@{ $slot_access }, \@_ ];";
}
$code .= "\n" . $self->_inline_check_coercion($potential_new_val);
$code .= "\n" . $self->_inline_check_constraint($potential_new_val);
$code .= "\n"
- . $self->_inline_get_old_value_for_trigger( $inv, $value_name );
+ . $self->_inline_get_old_value_for_trigger( $inv, '@_' );
$code .= "\n" . $self->_inline_store( $inv, $potential_new_val );
$code .= "\n" . $self->_inline_post_body(@_);
- $code .= "\n" . $self->_inline_trigger( $inv, $value_name, '@old' );
+ $code .= "\n" . $self->_inline_trigger( $inv, '@_', '@old' );
$code .= "\n}";