disturbingly, bound values appear to actually work
[scpubgit/DX.git] / lib / DX / Action / SetBoundValue.pm
CommitLineData
1e90aa03 1package DX::Action::SetBoundValue;
2
3use DX::Update::SetValue;
4use DX::Class;
5
6with 'DX::Role::Action';
7
8has target_path => (is => 'ro', required => 1);
9
10has rebind_path => (is => 'ro', required => 1);
11
12has new_value => (is => 'ro', required => 1);
13
14has inner_action => (is => 'ro', required => 1);
15
16sub dry_run {
17 my ($self, $hyp) = @_;
18 my ($outer_hyp, @inner_events) = $self->inner_action->dry_run($hyp);
19 my ($scope, @events) = $outer_hyp->scope->apply_updates(
20 DX::Update::SetValue->new(
21 target_path => $self->target_path,
22 new_value => $self->new_value,
23 )
24 );
25 my $new_bound = do {
26 my $targ = $scope;
27 $targ = $targ->get_member_at($_) for @{$self->rebind_path};
28 $targ;
29 };
30 my @actions = @{$outer_hyp->actions};
31 foreach my $idx (0.. $#actions) {
32 my $act = $actions[$idx];
33 if (
34 $act->isa('DX::Action::BindValue')
35 and join("\0", @{$act->target_path})
36 eq join("\0", @{$self->rebind_path})
37 ) {
38 my $bind = splice @actions, $idx, 1;
39 push @actions, $bind->but(new_value => $new_bound);
40 last;
41 }
42 }
43 return (
44 $outer_hyp->but(scope => $scope, actions => \@actions),
45 @inner_events, @events
46 );
47}
48
49sub run { die }
50
511;