1b9ee1ca727bc22de5a37ca4ca7c218165b72c5f
[scpubgit/DX.git] / lib / DX / Update / AddValue.pm
1 package DX::Update::AddValue;
2
3 use DX::Utils qw(VALUE_EXISTS);
4 use DX::Class;
5
6 with 'DX::Role::Update';
7
8 has new_value => (is => 'ro', required => 1);
9
10 sub apply_to {
11   my ($self, $scope) = @_;
12   my @path = my @whole_path = @{$self->target_path};
13   my $target = pop @path;
14   my $new_value = $self->new_value;
15   return (
16     $self->_with_value_at_path(
17       $scope, sub { $_[0]->with_member_at($target, $new_value) }, @path
18     ),
19     [ VALUE_EXISTS ,=> @whole_path ],
20   );
21 }
22
23 1;