package DX::QueryState;
use Types::Standard qw(HashRef);
+use DX::Scope;
+use DX::Hypothesis;
+use DX::SearchState;
+use DX::ResolvedPropositionSet;
+use DX::Value::Unset;
+use DX::ActionBuilder::UnsetValue;
+use DX::ActionPolicy::Allow;
+use DX::Utils qw(:builders);
use DX::Class;
has predicates => (is => 'ro', isa => HashRef[Predicate], required => 1);
is => 'ro', isa => PropositionSequence, required => 1
);
+has search_state => (
+ is => 'lazy', builder => sub {
+ $_[0]->new_search_state_for($_[0]->proposition_sequence)
+ },
+);
+
+sub new_search_state_for {
+ my ($self, $prop_seq) = @_;
+ my @local_names = map { keys %{$_->introduces_names} }
+ @{$prop_seq->members};
+ my $scope = DX::Scope->new(
+ predicates => $self->predicates,
+ globals => $self->globals,
+ locals => [
+ dict(
+ map +($_ => DX::Value::Unset->new(
+ identity_path => [ 0, $_ ],
+ action_builder => DX::ActionBuilder::UnsetValue->new(
+ target_path => [ 0, $_ ],
+ )
+ )
+ ), @local_names
+ )
+ ]
+ );
+ my $hyp = DX::Hypothesis->new(
+ scope => $scope,
+ resolved_propositions => DX::ResolvedPropositionSet->new_empty,
+ outstanding_propositions => $prop_seq->members,
+ actions => [],
+ action_policy => DX::ActionPolicy::Allow->new,
+ );
+ return DX::SearchState->new(
+ current_hypothesis => $hyp,
+ alternatives => [],
+ );
+}
+
+sub with_additional_proposition {
+ my ($self, $prop) = @_;
+ my $prop_seq = $self->proposition_sequence
+ ->but_append_proposition($prop);
+ $self->but(
+ proposition_sequence => $prop_seq,
+ search_state => $self->new_search_state_for($prop_seq)
+ );
+}
+
1;