1 package DX::QueryState;
6 use DX::ResolvedPropositionSet;
8 use DX::ActionBuilder::UnsetValue;
9 use DX::ActionPolicy::Allow;
10 use DX::Utils qw(:builders);
13 has predicates => (is => 'ro', isa => HashRef[Predicate], required => 1);
15 has globals => (is => 'ro', isa => DictValue, required => 1);
17 has proposition_sequence => (
18 is => 'ro', isa => PropositionSequence, required => 1
21 has search_process => (
22 is => 'lazy', isa => SearchProcess, builder => sub {
23 $_[0]->new_search_process_for($_[0]->proposition_sequence)
24 }, handles => { search_state => 'current_search_state' },
27 sub new_search_process_for {
28 my ($self, $prop_seq) = @_;
29 my @local_names = map { keys %{$_->introduced_names} }
30 @{$prop_seq->members};
31 my $scope = DX::Scope->new(
32 predicates => $self->predicates,
33 globals => $self->globals,
36 map +($_ => DX::Value::Unset->new(
37 action_builder => DX::ActionBuilder::UnsetValue->new(
38 target_path => [ 0, $_ ],
45 map +($_ => [ 0, $_ ]), @local_names
48 my $hyp = DX::Hypothesis->new(
50 resolved_propositions => DX::ResolvedPropositionSet->new_empty,
52 action_applications => [],
53 action_policy => DX::ActionPolicy::Allow->new,
55 return DX::SearchProcess->new_for($hyp, $prop_seq);
58 sub with_additional_proposition {
59 my ($self, $prop) = @_;
60 my $prop_seq = $self->proposition_sequence
61 ->with_additional_proposition($prop);
62 my $sol_ss = $self->new_search_process_for($prop_seq)
64 die "No solution\n" unless $sol_ss;
66 proposition_sequence => $prop_seq,
67 search_process => $sol_ss,
71 sub with_forced_backtrack {
73 my $next_ss = $self->search_process->find_next_solution;
74 die "No next solution\n" unless $next_ss;
75 $self->but(search_process => $next_ss);