sub expand {
my ($self, $type, @rest) = @_;
- $self->${\"_expand_${type}"}(@rest);
+ if ($self->can(my $expand_meth = "_expand_${type}")) {
+ return $self->$expand_meth(@rest);
+ }
+ return $self->_expand_call($type, @rest);
}
sub _expand_call {
my %by_id = %{$self->by_id};
my $state = $self->but(id_gen => { %{$self->id_gen} });
foreach my $name (keys %vars) {
-warn "assign: ${name}";
unless (blessed($vars{$name})) {
my $var = $vars{$name} = $state->allocate_var($name, $vars{$name});
$by_id{$var->id} = $var;
sub bind_var_then {
my ($self, $var, $value, $then) = @_;
- warn "Binding ".$var->id." to $value";
my $bound = $var->with_value($value);
$self->but(
by_id => { %{$self->by_id}, $var->id => $bound },
sub bind_stream_then {
my ($self, $var, $stream, $then) = @_;
- warn "Binding ".$var->id." to $stream";
my $bound = $var->with_stream($stream);
$self->but(
by_id => { %{$self->by_id}, $var->id => $bound },
my ($return) = @_;
local our $Nonlocal_Return = $return;
while (my $op = $state->next_op) {
-#::Dwarn($op);
$state = $op->run($state);
}
return $state;
$solver->add_rule(shell => [ 'S' ] => [ member_of => qw(S shells) ])
->add_rule(name => [ qw(T N) ],
[ constrain => [ qw(T N) ],
- sub { ::Dwarn(\@_); $_[0]->{name} eq $_[1] } ]
+ sub { $_[0]->{name} eq $_[1] } ]
)
->add_rule(shell_installed_on => [ qw(Shell Srv) ],
[ constrain => [ qw(Shell Srv) ],
$s = $solver->query(
[ qw(Shell Srv) ],
- [ call => shell => 'Shell' ],
- [ call => name => 'Shell', [ value => 'bash' ] ],
- [ call => server => 'Srv' ],
- [ call => shell_installed_on => qw(Shell Srv) ],
+ [ shell => 'Shell' ],
+ [ name => 'Shell', [ value => 'bash' ] ],
+ [ server => 'Srv' ],
+ [ shell_installed_on => qw(Shell Srv) ],
);
-::Dwarn($s->results);
+is_deeply(
+ [ sort map $_->{Srv}{name}, $s->results ],
+ [ qw(joe.example.com kitty.scsys.co.uk) ]
+);
done_testing;