Commit | Line | Data |
9d759b64 |
1 | package DX::Hypothesis; |
2 | |
3e465d5d |
3 | use DX::ActionPolicy::LockScope; |
4 | use Types::Standard qw(ArrayRef); |
4016201b |
5 | use DX::Utils qw(deparse); |
9d759b64 |
6 | use DX::Class; |
7 | |
3e465d5d |
8 | has scope => (is => 'ro', isa => Scope, required => 1); |
9d759b64 |
9 | |
3e465d5d |
10 | has resolved_propositions => ( |
11 | is => 'ro', isa => ResolvedPropositionSet, required => 1 |
12 | ); |
9d759b64 |
13 | |
3e465d5d |
14 | has actions => ( |
15 | is => 'ro', isa => ArrayRef[Action], required => 1 |
16 | ); |
17 | |
e442aff8 |
18 | has action_applications => ( |
19 | is => 'ro', isa => ArrayRef[Action], required => 1 |
20 | ); |
21 | |
3e465d5d |
22 | has action_policy => (is => 'ro', isa => ActionPolicy, required => 1); |
9d759b64 |
23 | |
24 | sub with_actions { |
25 | my ($self, @actions) = @_; |
26 | my $hyp = $self; |
9e8ed9ae |
27 | my @events; |
9d759b64 |
28 | foreach my $act (@actions) { |
3e465d5d |
29 | return undef unless $self->action_policy->allows($act); |
9e8ed9ae |
30 | ($hyp, my @these_events) = $act->dry_run($hyp); |
9d759b64 |
31 | return undef unless $hyp; |
9e8ed9ae |
32 | push @events, @these_events; |
9d759b64 |
33 | } |
ea0dbc2a |
34 | my ($still_resolved, @recheck) = $hyp->resolved_propositions |
35 | ->but_expire_for(@events); |
36 | return ( |
37 | $hyp->but(resolved_propositions => $still_resolved), |
38 | @recheck |
39 | ); |
9d759b64 |
40 | } |
41 | |
5787d20d |
42 | sub with_resolution { |
cdca8723 |
43 | my ($self, $prop, $depends, $actions) = @_; |
ea0dbc2a |
44 | (my $hyp, my @recheck) = $self->with_actions(@$actions); |
cdca8723 |
45 | return undef unless $hyp; |
77065529 |
46 | return ( |
47 | $hyp->but( |
48 | resolved_propositions => $self->resolved_propositions |
49 | ->with_resolution_for( |
50 | $prop, |
51 | $depends, |
52 | ), |
53 | ), |
54 | @recheck |
9d759b64 |
55 | ); |
56 | } |
57 | |
58 | 1; |