acc9306de7fef748f026979bcee224503fcc8afb
[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 => $value->but_set_action_builder($ab),
25     )
26   }
27   my $ab = DX::ActionBuilder::Normal->new(
28     target_path => $self->target_path,
29   );
30   DX::Action::SetValue->new(
31     target_path => $self->target_path,
32     new_value => $value->but_set_action_builder($ab)
33                        ->but_set_identity_path($self->target_path),
34   );
35 }
36
37 1;