Class: Puppet::Functions::InternalFunction Private

Inherits:
Function show all
Defined in:
lib/puppet/functions.rb

Overview

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

Note:

WARNING: This style of creating functions is not public. It is a system under development that will be used for creating “system” functions.

This is a private, internal, system for creating functions. It supports everything that the public function definition system supports as well as a few extra features.

Injection Support

The Function API supports injection of data and services. It is possible to make injection that takes effect when the function is loaded (for services and runtime configuration that does not change depending on how/from where in what context the function is called. It is also possible to inject and weave argument values into a call.

Injection of attributes


Injection of attributes is performed by one of the methods ‘attr_injected`, and `attr_injected_producer`. The injected attributes are available via accessor method calls.

Examples:

using injected attributes

Puppet::Functions.create_function('test') do
  attr_injected String, :larger, 'message_larger'
  attr_injected String, :smaller, 'message_smaller'
  def test(a, b)
    a > b ? larger() : smaller()
  end
end

Direct Known Subclasses

Hiera::PuppetFunction

Instance Attribute Summary

Attributes inherited from Pops::Functions::Function

#closure_scope, #loader

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Function

argument_mismatch, dispatch, local_types, new

Methods inherited from Pops::Functions::Function

#call, #call_function, dispatcher, #initialize, signatures

Constructor Details

This class inherits a constructor from Puppet::Pops::Functions::Function

Class Method Details

.builderObject

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.



647
648
649
# File 'lib/puppet/functions.rb', line 647

def self.builder
  InternalDispatchBuilder.new(dispatcher, Puppet::Pops::Types::PCallableType::DEFAULT, loader)
end

Instance Method Details

#call_function_with_scope(scope, function_name, *args, &block) ⇒ Object

Allows the implementation of a function to call other functions by name and pass the caller scope. The callable functions are those visible to the same loader that loaded this function (the calling function).

Parameters:

  • scope (Puppet::Parser::Scope)

    The caller scope

  • function_name (String)

    The name of the function

  • *args (Object)

    splat of arguments

Returns:

  • (Object)

    The result returned by the called function



661
662
663
# File 'lib/puppet/functions.rb', line 661

def call_function_with_scope(scope, function_name, *args, &block)
  internal_call_function(scope, function_name, args, &block)
end