initial partial sketch
[scpubgit/DX.git] / lib / DX / Hypothesis.pm
1 package DX::Hypothesis;
2
3 use DX::Class;
4
5 has scope => (is => 'ro', required => 1);
6
7 has resolved_propositions => (is => 'ro', required => 1);
8
9 has outstanding_propositions => (is => 'ro', required => 1);
10
11 has actions => (is => 'ro', required => 1);
12
13 sub with_actions {
14   my ($self, @actions) = @_;
15   my $hyp = $self;
16   foreach my $act (@actions) {
17     ($hyp, my @events) = $act->dry_run_against($hyp);
18     return undef unless $hyp;
19     $hyp = $hyp->but_recheck_for(@events);
20     return undef unless $hyp;
21   }
22   return $hyp;
23 }
24
25 sub but_recheck_for {
26   my ($self, @events) = @_;
27   my ($still_resolved, @recheck) = $self->resolved_propositions
28                                         ->but_expire_for(@events);
29   my $hyp = $self->but(resolved_propositions => $still_resolved);
30   $hyp = $_->but_recheck_against($hyp) or return undef for @recheck;
31   return $hyp;
32 }
33
34 sub resolve_head_dependent_on {
35   my ($self, $depends) = @_;
36   my ($first, @rest) = @{$self->outstanding_propositions};
37   $self->but(
38     resolved_propositions => $self->resolved_propositions
39                                   ->but_with_resolution(
40                                       proposition => $first,
41                                       depends_on => $depends,
42                                       at_depth => $self->scope->depth,
43                                     ),
44     outstanding_propositons => \@rest,
45   );
46 }
47
48 1;