provide and preserve aperture information
[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::Utils qw(VALUE_SET);
8 use DX::Class;
9
10 with 'DX::Role::ActionBuilder';
11
12 has target_path => (is => 'ro', required => 1);
13
14 sub aperture_for_set_value {
15   [ [ VALUE_SET ,=> @{$_[0]->target_path} ] ]
16 }
17
18 sub action_for_set_value {
19   my ($self, $value) = @_;
20   if (my $p = $value->value_path) {
21     my $ab = DX::ActionBuilder::BoundValue->new(
22       target_path => $self->target_path,
23       rebind_path => $self->target_path,
24       bound_to_path => $p,
25       inner_action_builder => $value->action_builder,
26     );
27     return DX::Action::BindValue->new(
28       target_path => $self->target_path,
29       new_value => $ab->apply_to_value($value, $value),
30     )
31   }
32   DX::ActionBuilder::Normal->new(
33     target_path => $self->target_path,
34   )->action_for_set_value($value);
35 }
36
37 1;