diff options
Diffstat (limited to 'lib/puppet/parser/ast/hostclass.rb')
-rw-r--r-- | lib/puppet/parser/ast/hostclass.rb | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb index 63900d0e3..8d4d01660 100644 --- a/lib/puppet/parser/ast/hostclass.rb +++ b/lib/puppet/parser/ast/hostclass.rb @@ -1,80 +1,80 @@ require 'puppet/parser/ast/definition' -class Puppet::Parser::AST - # The code associated with a class. This is different from definitions - # in that each class is a singleton -- only one will exist for a given - # node. - class HostClass < AST::Definition - @name = :class +# The code associated with a class. This is different from definitions +# in that each class is a singleton -- only one will exist for a given +# node. +class Puppet::Parser::AST::HostClass < Puppet::Parser::AST::Definition + @name = :class - # Are we a child of the passed class? Do a recursive search up our - # parentage tree to figure it out. - def child_of?(klass) - return false unless self.parentclass + # Are we a child of the passed class? Do a recursive search up our + # parentage tree to figure it out. + def child_of?(klass) + return false unless self.parentclass - if klass == self.parentobj - return true - else - return self.parentobj.child_of?(klass) - end + if klass == self.parentobj + return true + else + return self.parentobj.child_of?(klass) end + end - # Evaluate the code associated with this class. - def evaluate(options) - scope = options[:scope] - raise(ArgumentError, "Classes require resources") unless options[:resource] - # Verify that we haven't already been evaluated. This is - # what provides the singleton aspect. - if existing_scope = scope.compile.class_scope(self) - Puppet.debug "Class '%s' already evaluated; not evaluating again" % (classname == "" ? "main" : classname) - return nil - end - - scope.compile.catalog.tag(self.classname) + # Make sure our parent class has been evaluated, if we have one. + def evaluate(scope) + if parentclass and ! scope.catalog.resource(self.class.name, parentclass) + resource = parentobj.evaluate(scope) + end - pnames = nil - if pklass = self.parentobj - pklass.safeevaluate :scope => scope, :resource => options[:resource] + super + end - scope = parent_scope(scope, pklass) - pnames = scope.namespaces - end + # Evaluate the code associated with this class. + def evaluate_code(resource) + scope = resource.scope + # Verify that we haven't already been evaluated. This is + # what provides the singleton aspect. + if existing_scope = scope.compiler.class_scope(self) + Puppet.debug "Class '%s' already evaluated; not evaluating again" % (classname == "" ? "main" : classname) + return nil + end - # Don't create a subscope for the top-level class, since it already - # has its own scope. - unless options[:resource].title == :main - scope = subscope(scope, options[:resource]) - end + pnames = nil + if pklass = self.parentobj + parent_resource = resource.scope.compiler.catalog.resource(self.class.name, pklass.classname) + # This shouldn't evaluate if the class has already been evaluated. + pklass.evaluate_code(parent_resource) - if pnames - pnames.each do |ns| - scope.add_namespace(ns) - end - end + scope = parent_scope(scope, pklass) + pnames = scope.namespaces + end - # Set the class before we do anything else, so that it's set - # during the evaluation and can be inspected. - scope.compile.class_set(self.classname, scope) + # Don't create a subscope for the top-level class, since it already + # has its own scope. + scope = subscope(scope, resource) unless resource.title == :main - # Now evaluate our code, yo. - if self.code - return self.code.evaluate(:scope => scope) - else - return nil + # Add the parent scope namespaces to our own. + if pnames + pnames.each do |ns| + scope.add_namespace(ns) end end - def initialize(options) - @parentclass = nil - super + # Set the class before we evaluate the code, so that it's set during + # the evaluation and can be inspected. + scope.compiler.class_set(self.classname, scope) + + # Now evaluate our code, yo. + if self.code + return self.code.safeevaluate(scope) + else + return nil end + end - def parent_scope(scope, klass) - if s = scope.compile.class_scope(klass) - return s - else - raise Puppet::DevError, "Could not find scope for %s" % klass.classname - end + def parent_scope(scope, klass) + if s = scope.compiler.class_scope(klass) + return s + else + raise Puppet::DevError, "Could not find scope for %s" % klass.classname end end end |