sub run {
my ($self, $state) = @_;
($state, my %args) = $self->_expand_args($state, %{$self->_arg_map});
- my @vars = map $_->bound_value, @args{sort keys %args};
+ my @vars = map $state->resolve_value($_), @args{sort keys %args};
if ($self->constraint->(@vars)) {
return $state->then($self->next);
}
my $invoke = DX::Op::FromCode->new(
code => sub {
my ($self, $state) = @_;
- my $call = $var->bound_value->but(args => \@args);
+ my $call = $state->resolve_value($var)->but(args => \@args);
$state->but(scope => {})->then($call);
}
);
sub run {
my ($self, $state) = @_;
- $state->scope_var($self->var_name)->bound_value;
+ $state->resolve_value($state->scope_var($self->var_name));
$state->then($self->next);
}
);
my ($member, $of) = @args{qw(member of)};
die "member bound" if $member->is_bound;
- my $set = $state->facts->{$of->bound_value};
+ my $set = $state->facts->{$state->resolve_value($of)};
return $state->then($self->next)
->add_dependencies($member->id, $of->id)
->bind_root_set($member->id, $set)
my $invoke = DX::Op::FromCode->new(
code => sub {
my ($self, $state) = @_;
- my $op = $var->bound_value;
+ my $op = $state->resolve_value($var);
$state->then($op);
}
);
sub run {
my ($self, $state) = @_;
($state, my %args) = $self->_expand_args($state, %{$self->_arg_map});
- my @vars = map $_->bound_value, @args{sort keys %args};
+ my @vars = map $state->resolve_value($_), @args{sort keys %args};
my $observer = $self->builder->(@vars);
$state->return_from_run(
DX::ObservationRequired->new(
foreach my $i (0..$#arg_names) {
if ($req->[$i] eq '+') {
next CASE unless $args[$i]->is_bound;
- $_{$arg_names[$i]} = $args[$i]->bound_value;
+ $_{$arg_names[$i]} = $state->resolve_value($args[$i]);
} elsif ($req->[$i] eq '-') {
next CASE if $args[$i]->is_bound;
}
$state, map +($_ => $self->$_), qw(of name value)
);
die "property name must be bound" unless $args{name}->is_bound;
- my $name = $args{name}->bound_value;
+ my $name = $state->resolve_value($args{name});
if ($args{of}->is_bound) {
if ($args{value}->is_bound) {
- if ($args{of}->bound_value->$name eq $args{value}->bound_value) {
+ if ($state->resolve_value($args{of})->$name
+ eq $state->resolve_value($args{value})) {
return $state->add_dependencies(
$args{of}->id => $args{value}->id,
$args{value}->id => $args{of}->id,
}
return $state->backtrack;
}
- my $value = $args{of}->bound_value;
+ my $value = $state->resolve_value($args{of});
if ($value->can("has_${name}") and not $value->${\"has_${name}"}) {
return $state->backtrack;
}
sub value_for {
my ($self, $name) = @_;
- $self->_state->scope_var($name)->bound_value;
+ my $state = $self->_state;
+ $state->resolve_value($state->scope_var($name));
+}
+
+sub all_values {
+ my ($self) = @_;
+ return +{ map +($_ => $self->value_for($_)), $self->var_names };
}
1;
},
);
-has facts => (is => 'ro', required => 1);
+has facts => (is => 'ro', default => sub { {} });
has observation_policy => (is => 'ro');
$self->by_id->{$self->scope->{$name}};
}
+sub resolve_value {
+ my ($self, $var) = @_;
+ $var->bound_value;
+}
+
sub allocate_var {
my ($self, $name, $var, $id_gen) = @_;
my $id = join('_', $name, ++($id_gen->{$name}||='000'));