1 package DX::Role::BoundValueAction;
5 with 'DX::Role::Action';
7 has target_path => (is => 'ro', required => 1);
9 has bound_to_path => (is => 'ro', required => 1);
11 has rebind_path => (is => 'ro', required => 1);
13 has new_value => (is => 'ro', required => 1);
15 has inner_action => (is => 'ro', required => 1);
17 requires 'update_class';
20 my ($self, $hyp) = @_;
21 my ($outer_hyp, @inner_events) = $self->inner_action->dry_run(
23 action_applications => [ @{$hyp->action_applications}, $self ],
26 my $new_bound_to = do {
27 my $targ = $outer_hyp->scope;
28 $targ = $targ->get_member_at($_) for @{$self->bound_to_path};
31 my $new_ab = DX::ActionBuilder::BoundValue->new(
32 target_path => $self->target_path,
33 rebind_path => $self->rebind_path,
34 bound_to_path => $self->bound_to_path,
35 inner_action_builder => $new_bound_to->action_builder
37 my $value_with_ab = $new_ab->apply_to_value($self->new_value, $new_bound_to);
38 my ($scope, @events) = $outer_hyp->scope->apply_updates(
39 $self->update_class->new(
40 target_path => $self->target_path,
41 new_value => $value_with_ab,
46 $targ = $targ->get_member_at($_) for @{$self->rebind_path};
49 my @actions = @{$outer_hyp->actions};
50 foreach my $idx (0.. $#actions) {
51 my $act = $actions[$idx];
53 $act->isa('DX::Action::BindValue')
54 and join("\0", @{$act->target_path})
55 eq join("\0", @{$self->rebind_path})
57 my $bind = splice @actions, $idx, 1;
58 push @actions, $bind->but(new_value => $new_bound);
63 $outer_hyp->but(scope => $scope, actions => \@actions),
64 @inner_events, @events