diff options
| author | Luke Kanies <luke@reductivelabs.com> | 2010-01-06 17:42:42 -0800 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | b82b4ef04282ca0006931562f60459a1591b6268 (patch) | |
| tree | 31b77674c07a382a46af8773a81826a6e52c20b3 /lib/puppet/parser | |
| parent | 644ad7e41880fe8c9e73a099e9d6644e19828f46 (diff) | |
| download | puppet-b82b4ef04282ca0006931562f60459a1591b6268.tar.gz puppet-b82b4ef04282ca0006931562f60459a1591b6268.tar.xz puppet-b82b4ef04282ca0006931562f60459a1591b6268.zip | |
All non-transient parser references are gone
We now use references to the ResourceTypeCollection
instances through the environment, which is much cleaner.
The next step is to remove the Interpreter class.
Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'lib/puppet/parser')
| -rw-r--r-- | lib/puppet/parser/compiler.rb | 26 | ||||
| -rw-r--r-- | lib/puppet/parser/interpreter.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/parser/resource/reference.rb | 20 | ||||
| -rw-r--r-- | lib/puppet/parser/resource_type.rb | 1 | ||||
| -rw-r--r-- | lib/puppet/parser/resource_type_collection_helper.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/scope.rb | 17 | ||||
| -rw-r--r-- | lib/puppet/parser/templatewrapper.rb | 6 |
7 files changed, 40 insertions, 35 deletions
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb index 51df86ec6..f9c8f70ae 100644 --- a/lib/puppet/parser/compiler.rb +++ b/lib/puppet/parser/compiler.rb @@ -5,12 +5,16 @@ require 'puppet/node' require 'puppet/resource/catalog' require 'puppet/util/errors' +require 'puppet/parser/resource_type_collection_helper' + # Maintain a graph of scopes, along with a bunch of data # about the individual catalog we're compiling. class Puppet::Parser::Compiler include Puppet::Util include Puppet::Util::Errors - attr_reader :parser, :node, :facts, :collections, :catalog, :node_scope, :resources + include Puppet::Parser::ResourceTypeCollectionHelper + + attr_reader :node, :facts, :collections, :catalog, :node_scope, :resources # Add a collection to the global list. def add_collection(coll) @@ -48,7 +52,7 @@ class Puppet::Parser::Compiler # Do we use nodes found in the code, vs. the external node sources? def ast_nodes? - parser.nodes? + known_resource_types.nodes? end # Store the fact that we've evaluated a class @@ -138,13 +142,8 @@ class Puppet::Parser::Compiler @catalog.resource(*args) end - # Set up our compile. We require a parser - # and a node object; the parser is so we can look up classes - # and AST nodes, and the node has all of the client's info, - # like facts and environment. - def initialize(node, parser, options = {}) + def initialize(node, options = {}) @node = node - @parser = parser options.each do |param, value| begin @@ -163,7 +162,6 @@ class Puppet::Parser::Compiler def newscope(parent, options = {}) parent ||= topscope options[:compiler] = self - options[:parser] ||= self.parser scope = Puppet::Parser::Scope.new(options) scope.parent = parent scope @@ -189,10 +187,10 @@ class Puppet::Parser::Compiler # Now see if we can find the node. astnode = nil @node.names.each do |name| - break if astnode = @parser.node(name.to_s.downcase) + break if astnode = known_resource_types.node(name.to_s.downcase) end - unless (astnode ||= @parser.node("default")) + unless (astnode ||= known_resource_types.node("default")) raise Puppet::ParseError, "Could not find default node or by name with '%s'" % node.names.join(", ") end @@ -270,7 +268,7 @@ class Puppet::Parser::Compiler # Find and evaluate our main object, if possible. def evaluate_main - @main = @parser.find_hostclass("", "") || @parser.newclass("") + @main = known_resource_types.find_hostclass("", "") || known_resource_types.add(Puppet::Parser::ResourceType.new(:hostclass, "")) @topscope.source = @main @main_resource = Puppet::Parser::Resource.new(:type => "class", :title => :main, :scope => @topscope, :source => @main) @topscope.resource = @main_resource @@ -351,7 +349,7 @@ class Puppet::Parser::Compiler # Initialize the top-level scope, class, and resource. def init_main # Create our initial scope and a resource that will evaluate main. - @topscope = Puppet::Parser::Scope.new(:compiler => self, :parser => self.parser) + @topscope = Puppet::Parser::Scope.new(:compiler => self) end # Set up all of our internal variables. @@ -371,7 +369,7 @@ class Puppet::Parser::Compiler # For maintaining the relationship between scopes and their resources. @catalog = Puppet::Resource::Catalog.new(@node.name) - @catalog.version = @parser.version + @catalog.version = known_resource_types.version # local resource array to maintain resource ordering @resources = [] diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 1b158209d..eea9afcad 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -19,9 +19,8 @@ class Puppet::Parser::Interpreter # evaluate our whole tree def compile(node) - raise Puppet::ParseError, "Could not parse configuration; cannot compile on node %s" % node.name unless env_parser = parser(node.environment) begin - return Puppet::Parser::Compiler.new(node, env_parser).compile.to_resource + return Puppet::Parser::Compiler.new(node).compile.to_resource rescue => detail puts detail.backtrace if Puppet[:trace] raise Puppet::Error, detail.to_s + " on node %s" % node.name diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/parser/resource/reference.rb index 3ef981258..bb50efdce 100644 --- a/lib/puppet/parser/resource/reference.rb +++ b/lib/puppet/parser/resource/reference.rb @@ -3,12 +3,15 @@ require 'puppet/resource/reference' require 'puppet/file_collection/lookup' require 'puppet/parser/yaml_trimmer' +require 'puppet/parser/resource_type_collection_helper' + # A reference to a resource. Mostly just the type and title. class Puppet::Parser::Resource::Reference < Puppet::Resource::Reference include Puppet::Parser::YamlTrimmer include Puppet::FileCollection::Lookup include Puppet::Util::MethodHelper include Puppet::Util::Errors + include Puppet::Parser::ResourceTypeCollectionHelper attr_accessor :builtin, :file, :line, :scope @@ -39,21 +42,18 @@ class Puppet::Parser::Resource::Reference < Puppet::Resource::Reference unless defined? @definedtype case self.type when "Class" # look for host classes - if self.title == :main - tmp = @scope.find_hostclass("") - else - unless tmp = @scope.parser.hostclass(self.title) - fail Puppet::ParseError, "Could not find class '%s'" % self.title - end + name = self.title == :main ? "" : self.title + unless tmp = known_resource_types.find_hostclass("", name) + fail Puppet::ParseError, "Could not find '#{title}' class" end when "Node" # look for node definitions - unless tmp = @scope.parser.node(self.title) + unless tmp = known_resource_types.node(self.title) fail Puppet::ParseError, "Could not find node '%s'" % self.title end else # normal definitions # The resource type is capitalized, so we have to downcase. Really, # we should have a better interface for finding these, but eh. - tmp = @scope.parser.definition(self.type.downcase) + tmp = known_resource_types.definition(self.type.downcase) end if tmp @@ -66,6 +66,10 @@ class Puppet::Parser::Resource::Reference < Puppet::Resource::Reference @definedtype end + def environment + scope.environment + end + def initialize(hash) set_options(hash) requiredopts(:type, :title) diff --git a/lib/puppet/parser/resource_type.rb b/lib/puppet/parser/resource_type.rb index 3dbcbcb62..c0d7f69ed 100644 --- a/lib/puppet/parser/resource_type.rb +++ b/lib/puppet/parser/resource_type.rb @@ -27,6 +27,7 @@ class Puppet::Parser::ResourceType def evaluate_code(resource) # Create a new scope. scope = subscope(resource.scope, resource) + scope.compiler.class_set(name, scope) set_resource_parameters(resource, scope) diff --git a/lib/puppet/parser/resource_type_collection_helper.rb b/lib/puppet/parser/resource_type_collection_helper.rb index 4f66c773a..51ccdc061 100644 --- a/lib/puppet/parser/resource_type_collection_helper.rb +++ b/lib/puppet/parser/resource_type_collection_helper.rb @@ -1,3 +1,5 @@ +require 'puppet/parser/resource_type_collection' + module Puppet::Parser::ResourceTypeCollectionHelper def known_resource_types environment.known_resource_types diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index c32db357f..1f7fd7188 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -6,7 +6,10 @@ require 'puppet/parser/templatewrapper' require 'puppet/transportable' require 'strscan' +require 'puppet/parser/resource_type_collection_helper' + class Puppet::Parser::Scope + include Puppet::Parser::ResourceTypeCollectionHelper require 'puppet/parser/resource' AST = Puppet::Parser::AST @@ -15,7 +18,7 @@ class Puppet::Parser::Scope include Enumerable include Puppet::Util::Errors - attr_accessor :level, :parser, :source, :resource + attr_accessor :level, :source, :resource attr_accessor :base, :keyword, :nodescope attr_accessor :top, :translated, :compiler attr_accessor :parent @@ -25,15 +28,15 @@ class Puppet::Parser::Scope compiler.catalog end + def environment + compiler.environment + end + # Proxy accessors def host @compiler.node.name end - def interpreter - @compiler.interpreter - end - # Is the value true? This allows us to control the definition of truth # in one place. def self.true?(value) @@ -84,7 +87,7 @@ class Puppet::Parser::Scope def find_hostclass(name) @namespaces.each do |namespace| - if r = parser.find_hostclass(namespace, name) + if r = known_resource_types.find_hostclass(namespace, name) return r end end @@ -93,7 +96,7 @@ class Puppet::Parser::Scope def find_definition(name) @namespaces.each do |namespace| - if r = parser.find_definition(namespace, name) + if r = known_resource_types.find_definition(namespace, name) return r end end diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb index b2eb3c422..61c74e970 100644 --- a/lib/puppet/parser/templatewrapper.rb +++ b/lib/puppet/parser/templatewrapper.rb @@ -67,14 +67,12 @@ class Puppet::Parser::TemplateWrapper end def file=(filename) - unless @file = Puppet::Parser::Files.find_template(filename, scope.compiler.environment) + unless @file = Puppet::Parser::Files.find_template(filename, scope.compiler.environment.to_s) raise Puppet::ParseError, "Could not find template '%s'" % filename end # We'll only ever not have a parser in testing, but, eh. - if scope.parser - scope.parser.watch_file(file) - end + scope.known_resource_types.watch_file(file) @string = File.read(file) end |
