e2c705e976161dd9721425500b3a576db0d10e21
[scpubgit/DX.git] / lib / DX / Step / Normal.pm
1 package DX::Step::Normal;
2
3 use Types::Standard qw(ArrayRef);
4 use DX::Utils qw(deparse);
5 use DX::Class;
6
7 with 'DX::Role::Step';
8
9 has actions => (is => 'ro', isa => ArrayRef[Action], required => 1);
10
11 has depends_on => (is => 'ro', isa => DependencyGroupList, required => 1);
12
13 has alternative_step => (is => 'ro', isa => Step);
14
15 sub but_with_dependencies_on {
16   my ($self, @deps) = @_;
17   $self->but(depends_on => [ @{$self->depends_on}, @deps ]);
18 }
19
20 sub but_with_alternative_step {
21   my ($self, $step) = @_;
22   bless { %$self, alternative_step => $step }, ref($self);
23 }
24
25 sub apply_to {
26   my ($self, $old_hyp) = @_;
27   return ($self->_apply_to_hyp($old_hyp), $self->alternative_step);
28 }
29
30 sub _apply_to_hyp {
31   my ($self, $old_hyp) = @_;
32   return undef unless my $hyp = $old_hyp->with_actions(@{$self->actions});
33   return $hyp->resolve_head_dependent_on($self->depends_on);
34 }
35
36 1;