11890cafc6e0ab45a7311ab326577c60865e8f93
[scpubgit/DX.git] / lib / DX / Step / Normal.pm
1 package DX::Step::Normal;
2
3 use Types::Standard qw(ArrayRef);
4 use DX::Class;
5
6 with 'DX::Role::Step';
7
8 has actions => (is => 'ro', isa => ArrayRef[Action], required => 1);
9
10 has depends_on => (is => 'ro', isa => DependencyGroupList, required => 1);
11
12 has alternative_step => (is => 'ro', isa => Step);
13
14 sub but_with_dependencies_on {
15   my ($self, @deps) = @_;
16   $self->but(depends_on => [ @{$self->depends_on}, @deps ]);
17 }
18
19 sub but_with_alternative_step {
20   my ($self, $step) = @_;
21   bless { %$self, alternative_step => $step }, ref($self);
22 }
23
24 sub apply_to {
25   my ($self, $old_hyp) = @_;
26 #::Dwarn($self->depends_on);
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;