1 package DX::Hypothesis;
3 use DX::ActionPolicy::LockScope;
4 use Types::Standard qw(ArrayRef);
7 has scope => (is => 'ro', isa => Scope, required => 1);
9 has resolved_propositions => (
10 is => 'ro', isa => ResolvedPropositionSet, required => 1
13 has outstanding_propositions => (
14 is => 'ro', isa => ArrayRef[Proposition], required => 1
18 is => 'ro', isa => ArrayRef[Action], required => 1
21 has action_policy => (is => 'ro', isa => ActionPolicy, required => 1);
23 sub head_proposition { shift->outstanding_propositions->[0] }
26 my ($self, @actions) = @_;
28 foreach my $act (@actions) {
29 return undef unless $self->action_policy->allows($act);
30 ($hyp, my @events) = $act->dry_run($hyp);
31 return undef unless $hyp;
32 $hyp = $hyp->but_recheck_for(@events);
33 return undef unless $hyp;
39 my ($self, @events) = @_;
40 my ($still_resolved, @recheck) = $self->resolved_propositions
41 ->but_expire_for(@events);
42 return $self unless @recheck;
44 my $ap = DX::ActionPolicy::LockScope->new(
45 lock_to_depth => $self->scope->depth,
46 next_policy => $self->action_policy,
49 # we should probably be doing something about pruning the scope
50 # but that's completely pointless until we have rules
52 my $hyp = ref($self)->new(
53 scope => $self->scope,
54 resolved_propositions => DX::ResolvedPropositionSet->new_empty,
55 outstanding_propositions => \@recheck,
60 my $ss = DX::SearchState->new_for($hyp);
62 return undef unless my $sol_ss = $ss->find_solution;
64 my $sol_rps = $sol_ss->current_hypothesis->resolved_propositions;
66 my $rps = $still_resolved;
68 $rps = $rps->with_updated_dependencies_for(
69 $_, $sol_rps->dependencies_for($_)
72 return $self->but(resolved_propositions => $rps);
75 sub resolve_head_dependent_on {
76 my ($self, $depends) = @_;
77 my ($first, @rest) = @{$self->outstanding_propositions};
79 resolved_propositions => $self->resolved_propositions
80 ->with_resolution_for(
84 outstanding_propositions => \@rest,