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