separate scope setup in rule bodies into its own op
[scpubgit/DKit.git] / lib / DX / Op / CallRule.pm
index f97d187..17deac0 100644 (file)
@@ -17,29 +17,17 @@ has full_name => (is => 'lazy', builder => sub {
 
 sub run {
   my ($self, $state) = @_;
-  my @args = map {
-    if (!ref($_)) {
-      $state->scope_var($_)
-    } elsif (ref($_) eq 'ARRAY') {
-      if ($_->[0] eq 'value') {
-        +{ bound_value => $_->[1] };
-      } else {
-        die "Arrayref in argspec is not value";
-      }
-    } else {
-      die "Argspec incomprehensible";
-    }
-  } @{$self->rule_args};
+#warn "Call: ".$self->full_name;
+  my @args = map $self->_expand_argspec($state, $_), @{$self->rule_args};
   my @rules = @{$state->rule_set->rules->{$self->full_name}||[]};
   die "No rules for ${\$self->full_name}" unless @rules;
-  my $var = DX::Var->new(id => 'OR')
+  my $var = DX::Var->new(id => "rule:".$self->full_name)
                    ->with_stream(DX::ArrayStream->from_array(@rules));
   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(