my ($self, $name, $type, $values, $sub) = @_;
$sub = \&{$sub} if blessed($sub); # coderef if blessed
if (my $quoted = quoted_from_sub($sub)) {
+ my $local = 1;
+ if ($values eq '@_' || $values eq '$_[0]') {
+ $local = 0;
+ $values = '@_';
+ }
my $code = $quoted->[1];
if (my $captures = $quoted->[2]) {
my $cap_name = qq{\$${type}_captures_for_${name}};
$self->{captures}->{$cap_name} = \$captures;
Sub::Quote::inlinify(
- $code, $values, Sub::Quote::capture_unroll($cap_name, $captures, 6), 1
+ $code, $values, Sub::Quote::capture_unroll($cap_name, $captures, 6), $local
);
} else {
- Sub::Quote::inlinify($code, $values, undef, 1);
+ Sub::Quote::inlinify($code, $values, undef, $local);
}
} else {
my $cap_name = qq{\$${type}_for_${name}};
$do.'my ('.$code_args.') = ('.$args.'); '.$body.' }';
}
} else {
- $do.($local ? 'local ' : '').'@_ = ('.$args.'); '.$code.' }';
+ my $assign = '';
+ if ($local || $args ne '@_') {
+ $assign = ($local ? 'local ' : '').'@_ = ('.$args.'); ';
+ }
+ $do.$assign.$code.' }';
}
}