Commit | Line | Data |
efad53c4 |
1 | package DX::ActionBuilder::Normal; |
2 | |
0498469a |
3 | use DX::Action::SetValue; |
4 | use DX::Action::AddValue; |
efad53c4 |
5 | use DX::Class; |
6 | |
7 | with 'DX::Role::ActionBuilder'; |
8 | |
9 | has target_path => (is => 'ro', required => 1); |
10 | |
11 | sub action_for_set_value { |
12 | my ($self, $value) = @_; |
13 | DX::Action::SetValue->new( |
14 | target_path => $self->target_path, |
3a630a54 |
15 | new_value => $self->apply_to_value($value), |
efad53c4 |
16 | ); |
17 | } |
18 | |
0498469a |
19 | sub action_for_add_member { |
20 | my ($self, $at, $value) = @_; |
3a630a54 |
21 | my $ab = $self->specialize_for_member($at); |
0498469a |
22 | DX::Action::AddValue->new( |
3a630a54 |
23 | target_path => $ab->target_path, |
24 | new_value => $ab->apply_to_value($value), |
0498469a |
25 | ); |
26 | } |
27 | |
28 | sub action_for_remove_member { die 'WHUT' } |
29 | |
3a630a54 |
30 | sub apply_to_value { |
31 | my ($self, $value) = @_; |
7a5595d3 |
32 | my $new_value = $value->but_set_action_builder($self); |
3a630a54 |
33 | return $new_value unless $new_value->isa('DX::Value::Dict'); |
34 | my %m = %{$new_value->members}; |
35 | return $new_value->but( |
36 | members => { |
37 | map +($_ => $self->specialize_for_member($_)->apply_to_value($m{$_})), |
38 | keys %m, |
39 | }, |
40 | ); |
41 | } |
42 | |
43 | sub specialize_for_member { |
44 | my ($self, $at) = @_; |
45 | $self->but( |
46 | target_path => [ |
47 | @{$self->target_path}, |
48 | (ref($at) ? $at->string_value : $at) |
49 | ], |
50 | ); |
51 | } |
52 | |
efad53c4 |
53 | 1; |