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
15 is => 'ro', isa => ArrayRef[Action], required => 1
18 has action_applications => (
19 is => 'ro', isa => ArrayRef[Action], required => 1
22 has action_policy => (is => 'ro', isa => ActionPolicy, required => 1);
25 my ($self, @actions) = @_;
28 foreach my $act (@actions) {
29 return undef unless $self->action_policy->allows($act);
30 ($hyp, my @these_events) = $act->dry_run($hyp);
31 return undef unless $hyp;
32 push @events, @these_events;
34 my ($still_resolved, @recheck) = $hyp->resolved_propositions
35 ->but_expire_for(@events);
37 $hyp->but(resolved_propositions => $still_resolved),
43 my ($self, @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,
57 action_applications => [],
61 my $pseq = DX::PropositionSequence->new(
67 trace 'step.recheck.hyp' => $hyp;
69 my $ss = DX::SearchProcess->new_for($hyp, $pseq);
71 my $sol_ss = $ss->find_solution;
74 trace 'step.recheck.fail' => 'argh';
78 my $sol_rps = $sol_ss->current_hypothesis->resolved_propositions;
80 my $rps = $self->resolved_propositions;
82 $rps = $rps->with_updated_dependencies_for(
83 $_, $sol_rps->dependencies_for($_)
86 trace 'step.recheck.done' => 'yay';
88 return $self->but(resolved_propositions => $rps);
92 my ($self, $prop, $depends, $actions) = @_;
93 (my $hyp, my @recheck) = $self->with_actions(@$actions);
94 return undef unless $hyp;
96 $hyp = $hyp->but_recheck_for(@recheck);
97 return undef unless $hyp;
100 resolved_propositions => $self->resolved_propositions
101 ->with_resolution_for(