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_applications => (
23 is => 'ro', isa => ArrayRef[Action], required => 1
26 has action_policy => (is => 'ro', isa => ActionPolicy, required => 1);
29 my ($self, @actions) = @_;
31 foreach my $act (@actions) {
32 return undef unless $self->action_policy->allows($act);
33 ($hyp, my @events) = $act->dry_run($hyp);
34 return undef unless $hyp;
35 $hyp = $hyp->but_recheck_for(@events);
36 return undef unless $hyp;
42 my ($self, @events) = @_;
43 my ($still_resolved, @recheck) = $self->resolved_propositions
44 ->but_expire_for(@events);
45 return $self unless @recheck;
47 my $ap = DX::ActionPolicy::LockScope->new(
48 lock_to_depth => $self->scope->depth,
49 next_policy => $self->action_policy,
52 # we should probably be doing something about pruning the scope
53 # but that's completely pointless until we have rules
55 my $hyp = ref($self)->new(
56 scope => $self->scope,
57 resolved_propositions => DX::ResolvedPropositionSet->new_empty,
58 outstanding_propositions => \@recheck,
60 action_applications => [],
64 my $pseq = DX::PropositionSequence->new(
70 trace 'step.recheck.hyp' => $hyp;
72 my $ss = DX::SearchState->new_for($hyp, $pseq);
74 my $sol_ss = $ss->find_solution;
77 trace 'step.recheck.fail' => 'argh';
81 my $sol_rps = $sol_ss->current_hypothesis->resolved_propositions;
83 my $rps = $still_resolved;
85 $rps = $rps->with_updated_dependencies_for(
86 $_, $sol_rps->dependencies_for($_)
89 trace 'step.recheck.done' => 'yay';
91 return $self->but(resolved_propositions => $rps);
95 my ($self, $prop, $depends) = @_;
96 my ($first, @rest) = @{$self->outstanding_propositions};
98 resolved_propositions => $self->resolved_propositions
99 ->with_resolution_for(
103 outstanding_propositions => \@rest,