1 package DX::Action::SetBoundValue;
3 use DX::Update::SetValue;
6 with 'DX::Role::Action';
8 has target_path => (is => 'ro', required => 1);
10 has bound_to_path => (is => 'ro', required => 1);
12 has rebind_path => (is => 'ro', required => 1);
14 has new_value => (is => 'ro', required => 1);
16 has inner_action => (is => 'ro', required => 1);
19 my ($self, $hyp) = @_;
20 my ($outer_hyp, @inner_events) = $self->inner_action->dry_run(
22 action_applications => [ @{$hyp->action_applications}, $self ],
25 my $new_bound_to = do {
26 my $targ = $outer_hyp->scope;
27 $targ = $targ->get_member_at($_) for @{$self->bound_to_path};
30 my $new_ab = DX::ActionBuilder::BoundValue->new(
31 target_path => $self->target_path,
32 rebind_path => $self->rebind_path,
33 bound_to_path => $self->bound_to_path,
34 inner_action_builder => $new_bound_to->action_builder
36 my $value_with_ab = $new_ab->apply_to_value($self->new_value, $new_bound_to);
37 my ($scope, @events) = $outer_hyp->scope->apply_updates(
38 DX::Update::SetValue->new(
39 target_path => $self->target_path,
40 new_value => $value_with_ab,
45 $targ = $targ->get_member_at($_) for @{$self->rebind_path};
48 my @actions = @{$outer_hyp->actions};
49 foreach my $idx (0.. $#actions) {
50 my $act = $actions[$idx];
52 $act->isa('DX::Action::BindValue')
53 and join("\0", @{$act->target_path})
54 eq join("\0", @{$self->rebind_path})
56 my $bind = splice @actions, $idx, 1;
57 push @actions, $bind->but(new_value => $new_bound);
62 $outer_hyp->but(scope => $scope, actions => \@actions),
63 @inner_events, @events