my $invoke = DX::Op::FromCode->new(
code => sub {
my ($self, $state) = @_;
- my ($names, $body) = @{$var->bound_value};
- my %new; @new{@$names} = @args;
- $state->but(scope => {})->assign_vars(%new)->then($body);
+ my $call = $var->bound_value->but(args => \@args);
+ $state->but(scope => {})->then($call);
}
);
my $ret_op = DX::Op::SetScope->new(
--- /dev/null
+package DX::Op::SetupScope;
+
+use Moo;
+
+has arg_names => (is => 'ro', required => 1);
+
+with 'DX::Role::Op::WithArgs';
+
+sub run {
+ my ($self, $state) = @_;
+ my %new; @new{@{$self->arg_names}} = @{$self->args};
+ $state->assign_vars(%new)->then($self->next);
+}
+
+1;
--- /dev/null
+package DX::Role::Op::WithArgs;
+
+use Moo::Role;
+
+has args => (is => 'ro');
+
+with 'DX::Role::Op';
+
+1;
package DX::RuleSet;
use Moo;
+use DX::Op::SetupScope;
use DX::Op::CallRule;
use DX::Op::MemberOf;
use DX::Op::ApplyConstraint;
sub _make_rule {
my ($self, $vars, @body) = @_;
my $head = $self->expand_and_link(DX::Op::Return->new, @body);
- [ $vars, $head ];
+ DX::Op::SetupScope->new(arg_names => $vars, next => $head);
}
sub expand_and_link {