lift some of the rspace handling into the Resolution* classes
[scpubgit/DX.git] / lib / DX / ResolutionStrategy.pm
CommitLineData
7f385fb2 1package DX::ResolutionStrategy;
2
113f21b9 3use DX::Resolution;
7f385fb2 4use DX::Class;
5
6has action_prototypes => (is => 'ro', required => 1);
7
8has veracity_depends_on_builder => (is => 'ro', required => 1);
9
10has implementation_candidates => (is => 'ro', required => 1);
11
12has aperture => (is => 'lazy', builder => sub {
13 my ($self) = @_;
14 return [
15 # [ $thing, 'set_value' ] -> $thing->aperture_for_set_value
16 map @{$_->[0]->${\'aperture_for_'.$_[1]}()},
17 @{$self->action_prototypes}
18 ];
19});
20
113f21b9 21sub next_resolution {
22 my ($self) = @_;
23 return undef unless my ($first) = @{$self->implementation_candidates};
24 my @ap = @{$self->action_prototypes};
25 my @cand = @$first;
26 return DX::Resolution->new(
27 actions => [
28 map {
29 my ($inv, $type, @args) = @{$ap[$_]};
30 $inv->${\"action_for_${type}"}(@args, @{$cand[$_]});
31 } 0..$#ap
32 ],
33 veracity_depends_on => $self->veracity_depends_on_builder->(@cand),
34 );
35}
36
37sub remainder {
38 my ($self) = @_;
39 my ($first, @rest) = @{$self->implementation_candidates};
40 return () unless @rest;
41 return $self->but(implementation_candidates => \@rest);
42}
43
7f385fb2 441;