code: def set_input_dispatch_by_period(holder, period, array):
      
      array = holder._to_array(array)
  
      period_size = period.size
      period_unit = period.unit
  
      if holder.variable.definition_period == MONTH:
          cached_period_unit = periods.MONTH
      elif holder.variable.definition_period == YEAR:
          cached_period_unit = periods.YEAR
      else:
          raise ValueError('set_input_dispatch_by_period can be used only for yearly or monthly variables.')
  
      after_instant = period.start.offset(period_size, period_unit)
  
      # Cache the input data, skipping the existing cached months
      sub_period = period.start.period(cached_period_unit)
      while sub_period.start < after_instant:
          existing_array = holder.get_array(sub_period)
          if existing_array is None:
              holder._set(sub_period, array)
          else:
              # The array of the current sub-period is reused for the next ones.
              # TODO: refactor or document this behavior
              array = existing_array
          sub_period = sub_period.offset(1)
docs: This function can be declared as a ``set_input`` attribute of a variable.
  
          In this case, the variable will accept inputs on larger periods that its definition period, and the value for the larger period will be applied to all its subperiods.
  
          To read more about ``set_input`` attributes, check the `documentation <https://openfisca.org/doc/coding-the-legislation/35_periods.html#set-input-automatically-process-variable-inputs-defined-for-periods-not-matching-the-definition-period>`_.