class Puppet::Pal::CatalogCompiler
A CatalogCompiler is a compiler that builds a catalog of resources and dependencies as a side effect of evaluating puppet language code. When the compilation of the given input manifest(s)/code string/file is finished the catalog is complete for encoding and use. It is also possible to evaluate more strings within the same compilation context to add or remove things from the catalog.
@api public
Public Instance Methods
Returns a hash representation of the compiled catalog.
@api public
# File lib/puppet/pal/catalog_compiler.rb 44 def catalog_data_hash 45 catalog.to_data_hash 46 end
Compiles the result of additional evaluation taking place in a PAL catalog compilation. This will evaluate all lazy constructs until all have been evaluated, and will the validate the result.
This should be called if evaluating string or files of puppet logic after the initial compilation taking place by giving PAL a manifest or code-string. This method should be called when a series of evaluation should have reached a valid state (there should be no dangling relationships (to resources that does not exist).
As an alternative the methods `evaluate_additions` can be called without any requirements on consistency and then calling `validate` at the end.
Can be called multiple times.
@return [Void]
# File lib/puppet/pal/catalog_compiler.rb 83 def compile_additions 84 internal_compiler.compile_additions 85 end
Evaluates an AST obtained from `parse_string` or `parse_file` in topscope. If the ast is a `Puppet::Pops::Model::Program` (what is returned from the `parse` methods, any definitions in the program (that is, any function, plan, etc. that is defined will be made available for use).
@param ast [Puppet::Pops::Model::PopsObject] typically the returned `Program` from the parse methods, but can be any `Expression` @returns [Object] whatever the ast evaluates to
# File lib/puppet/pal/catalog_compiler.rb 55 def evaluate(ast) 56 if ast.is_a?(Puppet::Pops::Model::Program) 57 bridged = Puppet::Parser::AST::PopsBridge::Program.new(ast) 58 # define all catalog types 59 internal_compiler.environment.known_resource_types.import_ast(bridged, "") 60 bridged.evaluate(internal_compiler.topscope) 61 else 62 internal_evaluator.evaluate(topscope, ast) 63 end 64 end
Evaluates all lazy constructs that were produced as a side effect of evaluating puppet logic. Can be called multiple times.
# File lib/puppet/pal/catalog_compiler.rb 97 def evaluate_additions 98 internal_compiler.evaluate_additions 99 end
Attempts to evaluate AST for node defnintions puppet.com/docs/puppet/latest/lang_node_definitions.html if there are any.
# File lib/puppet/pal/catalog_compiler.rb 103 def evaluate_ast_node 104 internal_compiler.evaluate_ast_node 105 end
Returns true if this is a compiler that compiles a catalog. This implementation returns `true` @return [Boolean] true @api public
# File lib/puppet/pal/catalog_compiler.rb 23 def has_catalog? 24 true 25 end
Validates the state of the catalog (without performing evaluation of any elements requiring lazy evaluation. Can be called multiple times.
# File lib/puppet/pal/catalog_compiler.rb 90 def validate 91 internal_compiler.validate 92 end
Calls a block of code and yields a configured `JsonCatalogEncoder` to the block. @example Get resulting catalog as pretty printed Json
Puppet::Pal.in_environment(...) do |pal|
pal.with_catalog_compiler(...) do |compiler|
compiler.with_json_encoding { |encoder| encoder.encode }
end
end
@api public
# File lib/puppet/pal/catalog_compiler.rb 37 def with_json_encoding(pretty: true, exclude_virtual: true) 38 yield JsonCatalogEncoder.new(catalog, pretty: pretty, exclude_virtual: exclude_virtual) 39 end
Private Instance Methods
@api private
# File lib/puppet/pal/catalog_compiler.rb 14 def catalog 15 internal_compiler.catalog 16 end