Method: Puppet::Pops::Functions::Dispatcher#dispatch

Defined in:
lib/puppet/pops/functions/dispatcher.rb

#dispatch(instance, calling_scope, args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Dispatches the call to the first found signature (entry with matching type).

Parameters:

  • instance (Puppet::Functions::Function)
    • the function to call

  • calling_scope (T.B.D::Scope)
    • the scope of the caller

  • args (Array<Object>)
    • the given arguments in the form of an Array

Returns:

  • (Object)
    • what the called function produced



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/puppet/pops/functions/dispatcher.rb', line 34

def dispatch(instance, calling_scope, args, &block)

  dispatcher = find_matching_dispatcher(args, &block)
  unless dispatcher
    args_type = Puppet::Pops::Types::TypeCalculator.singleton.infer_set(block_given? ? args + [block] : args)
    raise ArgumentError, Puppet::Pops::Types::TypeMismatchDescriber.describe_signatures(instance.class.name, signatures, args_type)
  end
  if dispatcher.argument_mismatch_handler?
    msg = dispatcher.invoke(instance, calling_scope, args)
    raise ArgumentError, "'#{instance.class.name}' #{msg}"
  end

  catch(:next) do
    dispatcher.invoke(instance, calling_scope, args, &block)
  end
end