pervasive type constraints
[scpubgit/DX.git] / lib / DX / Role / SimpleAction.pm
1 package DX::Role::SimpleAction;
2
3 use DX::Role;
4
5 with 'DX::Role::Action';
6
7 has target_path => (is => 'ro', required => 1, isa => ValuePath);
8
9 has _updates => (is => 'lazy', isa => ArrayRef[Update]);
10
11 requires '_build__updates';
12
13 sub for_deparse {
14   my ($self) = @_;
15   [ statement => [
16     [ symbol => (split('::',ref($self)))[-1] ],
17     [ value_path => $self->target_path ],
18     $self->new_value,
19   ] ];
20 }
21
22 sub dry_run {
23   my ($self, $hyp) = @_;
24   my ($scope, @events) = $hyp->scope->apply_updates(@{$self->_updates});
25   return (
26     $hyp->but(
27       scope => $scope,
28       actions => [ @{$hyp->actions}, $self ],
29       action_applications => [ @{$hyp->action_applications}, $self ],
30     ),
31     @events
32   );
33 }
34
35 sub run { shift->updates }
36
37 1;