summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-02-11 17:24:02 -0600
committerLuke Kanies <luke@madstop.com>2008-02-11 17:24:02 -0600
commit6a4cf6c978e8c8aebba4ed0f16d3de7bb31a0ce0 (patch)
treedf96556dd073aa5d0c23c735a2456da8f144f6b9 /lib/puppet/parser
parent3b740ff7a6ab7127ec5e4935782c33245687c429 (diff)
downloadpuppet-6a4cf6c978e8c8aebba4ed0f16d3de7bb31a0ce0.tar.gz
puppet-6a4cf6c978e8c8aebba4ed0f16d3de7bb31a0ce0.tar.xz
puppet-6a4cf6c978e8c8aebba4ed0f16d3de7bb31a0ce0.zip
Fixed #1030 - class and definition evaluation has been significantly
refactored, fixing this problem and making the whole interplay between the classes, definitions, and nodes, and the Compile class much cleaner.
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/ast/definition.rb31
-rw-r--r--lib/puppet/parser/ast/hostclass.rb14
-rw-r--r--lib/puppet/parser/compile.rb10
3 files changed, 27 insertions, 28 deletions
diff --git a/lib/puppet/parser/ast/definition.rb b/lib/puppet/parser/ast/definition.rb
index bf57942d7..e3f6414c3 100644
--- a/lib/puppet/parser/ast/definition.rb
+++ b/lib/puppet/parser/ast/definition.rb
@@ -24,7 +24,12 @@ class Puppet::Parser::AST::Definition < Puppet::Parser::AST::Branch
# Create a resource that knows how to evaluate our actual code.
def evaluate(scope)
- resource = Puppet::Parser::Resource.new(:type => "class", :title => klass.classname, :scope => scope, :source => scope.source)
+ # Do nothing if the resource already exists; this provides the singleton nature classes need.
+ return if scope.catalog.resource(:class, self.classname)
+
+ resource = Puppet::Parser::Resource.new(:type => "class", :title => self.classname, :scope => scope, :source => scope.source)
+
+ scope.catalog.tag(*resource.tags)
scope.compile.store_resource(scope, resource)
@@ -91,23 +96,21 @@ class Puppet::Parser::AST::Definition < Puppet::Parser::AST::Branch
# Hunt down our class object.
def parentobj
- if @parentclass
- # Cache our result, since it should never change.
- unless defined?(@parentobj)
- unless tmp = find_parentclass
- parsefail "Could not find %s %s" % [self.class.name, @parentclass]
- end
+ return nil unless @parentclass
- if tmp == self
- parsefail "Parent classes must have dissimilar names"
- end
+ # Cache our result, since it should never change.
+ unless defined?(@parentobj)
+ unless tmp = find_parentclass
+ parsefail "Could not find %s parent %s" % [self.class.name, @parentclass]
+ end
- @parentobj = tmp
+ if tmp == self
+ parsefail "Parent classes must have dissimilar names"
end
- @parentobj
- else
- nil
+
+ @parentobj = tmp
end
+ @parentobj
end
# Create a new subscope in which to evaluate our code.
diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb
index 251d5eba6..4f2d00f0c 100644
--- a/lib/puppet/parser/ast/hostclass.rb
+++ b/lib/puppet/parser/ast/hostclass.rb
@@ -18,6 +18,15 @@ class Puppet::Parser::AST::HostClass < Puppet::Parser::AST::Definition
end
end
+ # Make sure our parent class has been evaluated, if we have one.
+ def evaluate(scope)
+ if parentclass and ! scope.catalog.resource(:class, parentclass)
+ resource = parentobj.evaluate(scope)
+ end
+
+ super
+ end
+
# Evaluate the code associated with this class.
def evaluate_code(resource)
scope = resource.scope
@@ -58,11 +67,6 @@ class Puppet::Parser::AST::HostClass < Puppet::Parser::AST::Definition
end
end
- def initialize(options)
- @parentclass = nil
- super
- end
-
def parent_scope(scope, klass)
if s = scope.compile.class_scope(klass)
return s
diff --git a/lib/puppet/parser/compile.rb b/lib/puppet/parser/compile.rb
index 46ce1cb9b..bceead271 100644
--- a/lib/puppet/parser/compile.rb
+++ b/lib/puppet/parser/compile.rb
@@ -115,16 +115,11 @@ class Puppet::Parser::Compile
if klass = scope.findclass(name)
found << name and next if class_scope(klass)
- # Create a resource to model this class, and then add it to the list
- # of resources.
- resource = Puppet::Parser::Resource.new(:type => "class", :title => klass.classname, :scope => scope, :source => scope.source)
-
- store_resource(scope, resource)
+ resource = klass.evaluate(scope)
# If they've disabled lazy evaluation (which the :include function does),
# then evaluate our resource immediately.
resource.evaluate unless lazy_evaluate
- @catalog.tag(klass.classname)
found << name
else
Puppet.info "Could not find class %s for %s" % [name, node.name]
@@ -412,9 +407,6 @@ class Puppet::Parser::Compile
# but they each refer back to the scope that created them.
@collections = []
- # A list of tags we've generated; most class names.
- @tags = []
-
# A graph for maintaining scope relationships.
@scope_graph = Puppet::SimpleGraph.new