}
$tcl->CreateCommand(query => sub {
- my (undef, undef, undef, $vars, $body) = @_;
- @last_q = expand_def($vars, $body);
+ my (undef, undef, undef, $body) = @_;
+ @last_q = expand_body($body);
do_query();
return;
});
$tcl->CreateCommand($rule => $rule_sub);
}
-$tcl->CreateCommand(exists => sub {
- my (undef, undef, undef, $vars, $body) = @_;
- push our @Body_Parts, [ exists => expand_def($vars, $body) ];
- return;
-});
-
$tcl->CreateCommand(foreach => sub {
my (undef, undef, undef, $var, $body, $each_body) = @_;
push our @Body_Parts, [
DX::Op::FromCode->new(
code => sub {
my ($self, $state) = @_;
- $state->bind_value($state->scope->{$coll_name} => $coll)
+ $state->assign_vars($coll_name => { bound_value => $coll })
->then($self->next);
},
next => $self->next
with 'DX::Role::Op';
-has var_name => (is => 'ro', required => 1);
-
sub run {
my ($self, $state) = @_;
- my $var = $state->scope_var($self->var_name);
- unless ($var->is_bound) {
- die "Can't materialize unbound ".$self->var_name;
+ foreach my $k (keys %{$state->scope}) {
+ my $var = $state->scope_var($k);
+ next unless $var->is_bound;
+ $state->resolve_value($var);
}
- $state->resolve_value($var);
$state->then($self->next);
}
has _state => (is => 'ro', required => 1, init_arg => 'state');
sub var_names {
- sort keys %{$_[0]->_state->scope};
+ grep $_[0]->_state->scope_var($_)->is_bound,
+ sort keys %{$_[0]->_state->scope};
}
sub actions {
}
sub _expand_op_materialize {
- my ($self, $var_name) = @_;
- DX::Op::Materialize->new(var_name => $var_name);
+ my ($self) = @_;
+ DX::Op::Materialize->new;
}
sub _expand_op_prop {
has observation_policy => (is => 'ro');
sub query {
- my ($self, $vars, @terms) = @_;
+ my ($self, @terms) = @_;
my $rule_set = $self->rule_set;
- push @terms, map +[ materialize => $_ ], @$vars;
- my $head = $rule_set->expand_and_link(undef, @terms);
+ my $head = $rule_set->expand_and_link(undef, @terms, [ 'materialize' ]);
my $state = DX::State->new(
next_op => $head,
return_stack => [],
last_choice => [],
facts => $self->facts,
rule_set => $rule_set,
- )->assign_vars(map +($_ => {}), @$vars);
+ );
return DX::ResultStream->new(
for_state => $state,
($self->observation_policy
server => [ 'S' ] => [ member_of => S => [ value => 'servers' ] ]
);
-my $s = $solver->query([ 'S' ], [ server => 'S' ]);
+my $s = $solver->query([ server => 'S' ]);
is_deeply([ map $_->value_for('S')->{name}, $s->results ], [ sort @servers ]);
);
$s = $solver->query(
- [ qw(Shell Srv) ],
[ shell => 'Shell' ],
[ name => 'Shell', [ value => 'bash' ] ],
[ server => 'Srv' ],
sub paths_for_simple {
join ' ', map $_->value_for('PS')->path, $solver->query(
- [ qw(PS) ], [ path_status => 'PS' ], @_
+ [ path_status => 'PS' ], @_
)->results;
}
throws_ok {
$solver->query(
- [ qw(PS) ],
- [ path_status_at => 'PS', [ value => '.ssh' ] ]
+ [ path_status_at => 'PS', [ value => '.ssh' ] ]
)->results
} qr/ARGH/;
lives_ok {
@res = $solver->query(
- [ qw(PS) ],
- [ path_status_at => 'PS', [ value => '.ssh' ] ]
+ [ path_status_at => 'PS', [ value => '.ssh' ] ]
)->results
};
$ob_res{'.ssh'} = $protos{'.ssh'};
sub paths_for {
- join ' ', map $_->value_for('PS')->path, $solver->query([ 'PS' ], @_)->results;
+ join ' ', map $_->value_for('PS')->path, $solver->query(@_)->results;
}
is(
$solver->{observation_policy} = sub { 1 };
sub dot_ssh_query {
- $solver->query([ 'PS' ], [ directory_at => 'PS' => [ value => '.ssh' ] ]);
+ $solver->query([ directory_at => 'PS' => [ value => '.ssh' ] ]);
}
is_deeply(
%ob_res = %empty;
sub keys_file {
- $solver->query([ qw(D F) ],
+ $solver->query(
[ directory_at => 'D' => \'.ssh' ],
[ file_in => 'D' => \'authorized_keys' => 'F' ],
);
);
$solver->add_rule(has_shell => [ 'Srv', 'Shell' ],
- [ exists => [ qw(Name SI) ] =>
- [ member_of => 'SI', \'shell_installed' ],
- [ prop => 'SI' => \'server' => 'Name' ],
- [ prop => 'Srv' => \'name' => 'Name' ],
- [ prop => 'SI' => \'shell' => 'Shell' ]
- ],
+ [ member_of => 'SI', \'shell_installed' ],
+ [ prop => 'SI' => \'server' => 'Name' ],
+ [ prop => 'Srv' => \'name' => 'Name' ],
+ [ prop => 'SI' => \'shell' => 'Shell' ]
);
-my @r = $solver->query([ 'X' ],
+my @r = $solver->query(
[ findall => X => S =>
[ member_of => 'S', \'server' ],
[ has_shell => 'S', \'bash' ],
[ qw(one three four) ]
);
-@r = $solver->query([],
+@r = $solver->query(
[ foreach => S => [ [ member_of => 'S', \'server' ] ],
[ [ has_shell => 'S' => \'bash' ] ] ]
)->results;
$solver->add_rule(has_any_shell => [ 'S' ] => [ has_shell => 'S' => \'bash' ]);
$solver->add_rule(has_any_shell => [ 'S' ] => [ has_shell => 'S' => \'csh' ]);
-@r = $solver->query([],
+@r = $solver->query(
[ foreach => S => [ [ member_of => 'S', \'server' ] ],
[ [ has_any_shell => 'S' ] ] ]
)->results;