X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDX%2FHypothesis.pm;h=c3a8fe4cd15fce2a4fbd20ae78b38f5d5556750b;hb=HEAD;hp=71477e817071b3c3dd1758bec6d3e1aef46171cf;hpb=4016201bfc4050f0d4c2d79eab8e62f3dac99d43;p=scpubgit%2FDX.git diff --git a/lib/DX/Hypothesis.pm b/lib/DX/Hypothesis.pm index 71477e8..c3a8fe4 100644 --- a/lib/DX/Hypothesis.pm +++ b/lib/DX/Hypothesis.pm @@ -1,7 +1,6 @@ package DX::Hypothesis; use DX::ActionPolicy::LockScope; -use Types::Standard qw(ArrayRef); use DX::Utils qw(deparse); use DX::Class; @@ -11,78 +10,47 @@ has resolved_propositions => ( is => 'ro', isa => ResolvedPropositionSet, required => 1 ); -has outstanding_propositions => ( - is => 'ro', isa => ArrayRef[Proposition], required => 1 +has actions => ( + is => 'ro', isa => ArrayRef[Action], required => 1 ); -has actions => ( +has action_applications => ( is => 'ro', isa => ArrayRef[Action], required => 1 ); has action_policy => (is => 'ro', isa => ActionPolicy, required => 1); -sub head_proposition { shift->outstanding_propositions->[0] } - sub with_actions { my ($self, @actions) = @_; my $hyp = $self; + my @events; foreach my $act (@actions) { return undef unless $self->action_policy->allows($act); - ($hyp, my @events) = $act->dry_run($hyp); - return undef unless $hyp; - $hyp = $hyp->but_recheck_for(@events); + ($hyp, my @these_events) = $act->dry_run($hyp); return undef unless $hyp; + push @events, @these_events; } - return $hyp; -} - -sub but_recheck_for { - my ($self, @events) = @_; - my ($still_resolved, @recheck) = $self->resolved_propositions - ->but_expire_for(@events); - return $self unless @recheck; - - my $ap = DX::ActionPolicy::LockScope->new( - lock_to_depth => $self->scope->depth, - next_policy => $self->action_policy, + my ($still_resolved, @recheck) = $hyp->resolved_propositions + ->but_expire_for(@events); + return ( + $hyp->but(resolved_propositions => $still_resolved), + @recheck ); - - # we should probably be doing something about pruning the scope - # but that's completely pointless until we have rules - - my $hyp = ref($self)->new( - scope => $self->scope, - resolved_propositions => DX::ResolvedPropositionSet->new_empty, - outstanding_propositions => \@recheck, - actions => [], - action_policy => $ap, - ); - - my $ss = DX::SearchState->new_for($hyp); - - return undef unless my $sol_ss = $ss->find_solution; - - my $sol_rps = $sol_ss->current_hypothesis->resolved_propositions; - - my $rps = $still_resolved; - - $rps = $rps->with_updated_dependencies_for( - $_, $sol_rps->dependencies_for($_) - ) for @recheck; - - return $self->but(resolved_propositions => $rps); } -sub resolve_head_dependent_on { - my ($self, $depends) = @_; - my ($first, @rest) = @{$self->outstanding_propositions}; - $self->but( - resolved_propositions => $self->resolved_propositions - ->with_resolution_for( - $first, - $depends, - ), - outstanding_propositions => \@rest, +sub with_resolution { + my ($self, $prop, $depends, $actions) = @_; + (my $hyp, my @recheck) = $self->with_actions(@$actions); + return undef unless $hyp; + return ( + $hyp->but( + resolved_propositions => $self->resolved_propositions + ->with_resolution_for( + $prop, + $depends, + ), + ), + @recheck ); }