MemberAt cut over to rspace/rstrat
[scpubgit/DX.git] / lib / DX / ActionBuilder / Null.pm
1 package DX::ActionBuilder::Null;
2
3 use DX::Class;
4
5 with 'DX::Role::ActionBuilder';
6
7 has target_path => (is => 'ro');
8
9 around target_path => sub {
10   my ($orig, $self) = (shift, shift);
11   return undef unless ref($self);
12   return $self->$orig(@_);
13 };
14
15 sub can_set_value { 0 }
16
17 sub action_for_set_value { undef }
18
19 sub can_add_member { 0 }
20
21 sub action_for_add_member { undef }
22
23 sub action_for_set_member { undef }
24
25 sub action_for_remove_member { undef }
26
27 sub specialize_for_member {
28   my ($self, $at) = @_;
29   return $self unless ref($self);
30   return $self unless my $path = $self->target_path;
31   return $self->but(
32     target_path => [ @{$self->target_path}, $at ]
33   );
34 }
35
36 sub apply_to_value {
37   my ($self, $value) = @_;
38   my $new_value = $value->but_set_action_builder($self);
39   return $new_value unless $new_value->isa('DX::Value::Dict');
40   my %m = %{$new_value->members};
41   return $new_value->but(
42     members => {
43       map +($_ => $self->specialize_for_member($_)->apply_to_value($m{$_})),
44         keys %m,
45     },
46   );
47 }
48
49 1;