format aperture in backtrack trace
[scpubgit/DX.git] / lib / DX / Hypothesis.pm
1 package DX::Hypothesis;
2
3 use DX::ActionPolicy::LockScope;
4 use Types::Standard qw(ArrayRef);
5 use DX::Utils qw(deparse);
6 use DX::Class;
7
8 has scope => (is => 'ro', isa => Scope, required => 1);
9
10 has resolved_propositions => (
11   is => 'ro', isa => ResolvedPropositionSet, required => 1
12 );
13
14 has actions => (
15   is => 'ro', isa => ArrayRef[Action], required => 1
16 );
17
18 has action_applications => (
19   is => 'ro', isa => ArrayRef[Action], required => 1
20 );
21
22 has action_policy => (is => 'ro', isa => ActionPolicy, required => 1);
23
24 sub with_actions {
25   my ($self, @actions) = @_;
26   my $hyp = $self;
27   my @events;
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;
33   }
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   );
40 }
41
42 sub with_resolution {
43   my ($self, $prop, $depends, $actions) = @_;
44   (my $hyp, my @recheck) = $self->with_actions(@$actions);
45   return undef unless $hyp;
46   return (
47     $hyp->but(
48       resolved_propositions => $self->resolved_propositions
49                                     ->with_resolution_for(
50                                         $prop,
51                                         $depends,
52                                       ),
53     ),
54     @recheck
55   );
56 }
57
58 1;