diff options
| author | Luke Kanies <luke@madstop.com> | 2008-02-11 17:24:02 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-02-11 17:24:02 -0600 |
| commit | 6a4cf6c978e8c8aebba4ed0f16d3de7bb31a0ce0 (patch) | |
| tree | df96556dd073aa5d0c23c735a2456da8f144f6b9 /lib/puppet/parser/ast | |
| parent | 3b740ff7a6ab7127ec5e4935782c33245687c429 (diff) | |
| download | puppet-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/ast')
| -rw-r--r-- | lib/puppet/parser/ast/definition.rb | 31 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/hostclass.rb | 14 |
2 files changed, 26 insertions, 19 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 |
