refactor action stuff to be recursive on dicts
[scpubgit/DX.git] / lib / DX / ActionBuilder / UnsetValue.pm
1 package DX::ActionBuilder::UnsetValue;
2
3 use DX::Action::SetValue;
4 use DX::ActionBuilder::Normal;
5 use DX::Action::BindValue;
6 use DX::ActionBuilder::BoundValue;
7 use DX::Class;
8
9 with 'DX::Role::ActionBuilder';
10
11 has target_path => (is => 'ro', required => 1);
12
13 sub action_for_set_value {
14   my ($self, $value) = @_;
15   if (my $p = $value->identity_path) {
16     my $ab = DX::ActionBuilder::BoundValue->new(
17       target_path => $self->target_path,
18       rebind_path => $self->target_path,
19       bound_to_path => $p,
20       inner_action_builder => $value->action_builder,
21     );
22     return DX::Action::BindValue->new(
23       target_path => $self->target_path,
24       new_value => $ab->apply_to_value($value, $value),
25     )
26   }
27   DX::ActionBuilder::Normal->new(
28     target_path => $self->target_path,
29   )->action_for_set_value($value);
30 }
31
32 1;