Class: Puppet::Parser::ScriptCompiler
- Includes:
- AbstractCompiler
- Defined in:
- lib/puppet/parser/script_compiler.rb
Overview
A Script “compiler” that does not support catalog operations
The Script compiler is “one shot” - it does not support rechecking if underlying source has changed or deal with possible errors in a cached environment.
Instance Attribute Summary collapse
- #environment ⇒ Object readonly private
-
#loaders ⇒ Puppet::Pops::Loader::Loaders
readonly
private
Access to the configured loaders for 4x.
- #node_name ⇒ Object readonly private
- #qualified_variables ⇒ Object readonly private
- #topscope ⇒ Object readonly private
Instance Method Summary collapse
-
#compile ⇒ Object
Evaluates the configured setup for a script + code in an environment with modules.
-
#context_overrides ⇒ Object
Constructs the overrides for the context.
-
#initialize(environment, node_name, for_agent = false) ⇒ ScriptCompiler
constructor
Create a script compiler for the given environment where errors are logged as coming from the given node_name.
-
#newscope(parent, options = {}) ⇒ Object
Having multiple named scopes hanging from top scope is not supported when scripting in the regular compiler this is used to create one named scope per class.
- #with_context_overrides(description = '', &block) ⇒ Object
Methods included from AbstractCompiler
Constructor Details
#initialize(environment, node_name, for_agent = false) ⇒ ScriptCompiler
Create a script compiler for the given environment where errors are logged as coming from the given node_name
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/puppet/parser/script_compiler.rb', line 76 def initialize(environment, node_name, for_agent = false) @environment = environment @node_name = node_name # Create the initial scope, it is needed early @topscope = Puppet::Parser::Scope.new(self) # Initialize loaders and Pcore if for_agent @loaders = Puppet::Pops::Loaders.new(environment, true) else @loaders = Puppet::Pops::Loaders.new(environment) end # Need to compute overrides here, and remember them, because we are about to # Expensive entries in the context are bound lazily. @context_overrides = context_overrides() # Resolutions of fully qualified variable names @qualified_variables = {} end |
Instance Attribute Details
#environment ⇒ Object (readonly)
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.
28 29 30 |
# File 'lib/puppet/parser/script_compiler.rb', line 28 def environment @environment end |
#loaders ⇒ Puppet::Pops::Loader::Loaders (readonly)
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.
Access to the configured loaders for 4x
25 26 27 |
# File 'lib/puppet/parser/script_compiler.rb', line 25 def loaders @loaders end |
#node_name ⇒ Object (readonly)
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.
31 32 33 |
# File 'lib/puppet/parser/script_compiler.rb', line 31 def node_name @node_name end |
#qualified_variables ⇒ Object (readonly)
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.
20 21 22 |
# File 'lib/puppet/parser/script_compiler.rb', line 20 def qualified_variables @qualified_variables end |
#topscope ⇒ Object (readonly)
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.
17 18 19 |
# File 'lib/puppet/parser/script_compiler.rb', line 17 def topscope @topscope end |
Instance Method Details
#compile ⇒ Object
Evaluates the configured setup for a script + code in an environment with modules
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/puppet/parser/script_compiler.rb', line 39 def compile Puppet[:strict_variables] = true Puppet[:strict] = :error # TRANSLATORS, "For running script" is not user facing Puppet.override(@context_overrides, "For running script") do # TRANSLATORS "main" is a function name and should not be translated result = Puppet::Util::Profiler.profile(_("Script: Evaluated main"), [:script, :evaluate_main]) { evaluate_main } if block_given? yield self else result end end rescue Puppet::ParseErrorWithIssue => detail detail.node = node_name Puppet.log_exception(detail) raise rescue => detail = "#{detail} on node #{node_name}" Puppet.log_exception(detail, ) raise Puppet::Error, , detail.backtrace end |
#context_overrides ⇒ Object
Constructs the overrides for the context
64 65 66 67 68 69 70 71 |
# File 'lib/puppet/parser/script_compiler.rb', line 64 def context_overrides { :current_environment => environment, :global_scope => @topscope, # 4x placeholder for new global scope :loaders => @loaders, # 4x loaders :rich_data => true, } end |
#newscope(parent, options = {}) ⇒ Object
Having multiple named scopes hanging from top scope is not supported when scripting in the regular compiler this is used to create one named scope per class. When scripting, the “main class” is just a container of the top level code to evaluate and it is not evaluated as a class added to a catalog. Since classes are not supported there is no need to support the concept of “named scopes” as all variables are local
- or in the top scope itself (notably, the $settings
-
namespace is initialized
as just a set of variables in that namespace - there is no named scope for ‘settings’ when scripting.
Keeping this method here to get specific error as being unsure if there are functions/logic that will call this. The AbstractCompiler defines this method, but maybe it does not have to (TODO).
111 112 113 |
# File 'lib/puppet/parser/script_compiler.rb', line 111 def newscope(parent, = {}) raise _('having multiple named scopes is not supported when scripting') end |