1 package DX::Hypothesis;
3 use DX::ActionPolicy::LockScope;
4 use Types::Standard qw(ArrayRef);
5 use DX::Utils qw(deparse);
8 has scope => (is => 'ro', isa => Scope, required => 1);
10 has resolved_propositions => (
11 is => 'ro', isa => ResolvedPropositionSet, required => 1
14 has outstanding_propositions => (
15 is => 'ro', isa => ArrayRef[Proposition], required => 1
19 is => 'ro', isa => ArrayRef[Action], required => 1
22 has action_policy => (is => 'ro', isa => ActionPolicy, required => 1);
24 sub head_proposition { shift->outstanding_propositions->[0] }
27 my ($self, @actions) = @_;
29 foreach my $act (@actions) {
30 return undef unless $self->action_policy->allows($act);
31 ($hyp, my @events) = $act->dry_run($hyp);
32 return undef unless $hyp;
33 $hyp = $hyp->but_recheck_for(@events);
34 return undef unless $hyp;
40 my ($self, @events) = @_;
41 my ($still_resolved, @recheck) = $self->resolved_propositions
42 ->but_expire_for(@events);
43 return $self unless @recheck;
45 my $ap = DX::ActionPolicy::LockScope->new(
46 lock_to_depth => $self->scope->depth,
47 next_policy => $self->action_policy,
50 # we should probably be doing something about pruning the scope
51 # but that's completely pointless until we have rules
53 my $hyp = ref($self)->new(
54 scope => $self->scope,
55 resolved_propositions => DX::ResolvedPropositionSet->new_empty,
56 outstanding_propositions => \@recheck,
61 my $ss = DX::SearchState->new_for($hyp);
63 return undef unless my $sol_ss = $ss->find_solution;
65 my $sol_rps = $sol_ss->current_hypothesis->resolved_propositions;
67 my $rps = $still_resolved;
69 $rps = $rps->with_updated_dependencies_for(
70 $_, $sol_rps->dependencies_for($_)
73 return $self->but(resolved_propositions => $rps);
76 sub resolve_head_dependent_on {
77 my ($self, $depends) = @_;
78 my ($first, @rest) = @{$self->outstanding_propositions};
80 resolved_propositions => $self->resolved_propositions
81 ->with_resolution_for(
85 outstanding_propositions => \@rest,