package DX::Role::Update;

use DX::Role;

has target_path => (is => 'ro', required => 1);

sub _with_value_at_path {
  my ($self, $scope, $final_value, @path) = @_;
  return $final_value->($scope) unless @path;
  my ($first, @rest) = @path;
  my $inner = $scope->get_member_at($first);
  my $value = (
    @rest
      ? $self->_with_value_at_path($inner, $final_value, @rest)
      : $final_value->($inner)
  );
  $scope->with_member_at($first, $value);
}

1;
