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