Method: Puppet::Pal::Compiler#evaluate_string

Defined in:
lib/puppet/pal/compiler.rb

#evaluate_string(puppet_code, source_file = nil) ⇒ 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.

Evaluates a string of puppet language code in top scope. A “source_file” reference to a source can be given - if not an actual file name, by convention the name should be bracketed with < > to indicate it is something symbolic; for example ‘<commandline>` if the string was given on the command line.

If the given ‘puppet_code` is `nil` or an empty string, `nil` is returned, otherwise the result of evaluating the puppet language string. The given string must form a complete and valid expression/statement as an error is raised otherwise. That is, it is not possible to divide a compound expression by line and evaluate each line individually.

Parameters:

  • puppet_code (String, nil)

    the puppet language code to evaluate, must be a complete expression/statement

  • source_file (String, nil) (defaults to: nil)

    an optional reference to a source (a file or symbolic name/location)

Returns:

  • (Object)

    what the ‘puppet_code` evaluates to



84
85
86
87
88
89
90
# File 'lib/puppet/pal/compiler.rb', line 84

def evaluate_string(puppet_code, source_file = nil)
  return nil if puppet_code.nil? || puppet_code == ''
  unless puppet_code.is_a?(String)
    raise ArgumentError, _("The argument 'puppet_code' must be a String, got %{type}") % { type: puppet_code.class }
  end
  evaluate(parse_string(puppet_code, source_file))
end