diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-02-27 22:21:44 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-02-27 22:21:44 +0000 |
commit | 8c821c09eebe117bd8b100b6dc416ded0588b979 (patch) | |
tree | aacd4fb7d966eae215917e5556e9e08eeb43bc53 /lib/puppet/parser/ast/hostclass.rb | |
parent | 37c10d176d8d3b7bb1920bbda66c6f0429b66730 (diff) | |
download | puppet-8c821c09eebe117bd8b100b6dc416ded0588b979.tar.gz puppet-8c821c09eebe117bd8b100b6dc416ded0588b979.tar.xz puppet-8c821c09eebe117bd8b100b6dc416ded0588b979.zip |
Mostly, this is a refactoring commit. There is one significant new feature,
though: overrides now only work within a class heirarchy, which is to say that
a subclass can override an element in a base class, but a child scope cannot
otherwise override an element in a base scope.
I've also done a good bit of refactoring, though; notably, AST#evaluate now
takes named arguments, and I changed the 'name' parameter to 'type' in all of
the Component classes (this was all internal, but was confusing as it was).
I also removed the need for the autonaming stuff -- it's now acceptable for
components not to have names, and everything behaves correctly. I haven't yet
removed the autoname code, though; I'll do that on the next commit.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@952 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/ast/hostclass.rb')
-rw-r--r-- | lib/puppet/parser/ast/hostclass.rb | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb index d6b323fb7..3952cd4dc 100644 --- a/lib/puppet/parser/ast/hostclass.rb +++ b/lib/puppet/parser/ast/hostclass.rb @@ -6,26 +6,45 @@ class Puppet::Parser::AST @name = :class attr_accessor :parentclass - def evaluate(scope,hash,objtype,objname) + #def evaluate(scope,hash,objtype,objname) + def evaluate(hash) + scope = hash[:scope] + objtype = hash[:type] + objname = hash[:name] + hash = hash[:arguments] # Verify that we haven't already been evaluated # FIXME The second subclass won't evaluate the parent class # code at all, and any overrides will throw an error. if scope.lookupclass(self.object_id) - Puppet.debug "%s class already evaluated" % @name + Puppet.debug "%s class already evaluated" % @type return nil end - if tmp = self.evalparent(scope, hash, objname) + # Default to creating a new context + newcontext = true + if parentscope = self.evalparent( + :scope => scope, :arguments => hash, :name => objname + ) # Override our scope binding with the parent scope # binding. This is quite hackish, but I can't think # of another way to make sure our scopes end up under # our parent scopes. - scope = tmp + scope = parentscope + + # But don't create a new context if our parent created one + newcontext = false end # just use the Component evaluate method, but change the type # to our own type - retval = super(scope,hash,@name,objname) + #retval = super(scope,hash,@name,objname) + retval = super( + :scope => scope, + :arguments => hash, + :type => @type, + :name => objname, + :newcontext => newcontext + ) # Set the mark after we evaluate, so we don't record it but # then encounter an error @@ -36,8 +55,14 @@ class Puppet::Parser::AST # Evaluate our parent class. Parent classes are evaluated in the # exact same scope as the children. This is maybe not a good idea # but, eh. - def evalparent(scope, args, name) + #def evalparent(scope, args, name) + def evalparent(hash) + scope = hash[:scope] + args = hash[:arguments] + name = hash[:name] if @parentclass + #scope.warning "parent class of %s is %s" % + # [@type, @parentclass.inspect] parentobj = nil begin @@ -65,13 +90,21 @@ class Puppet::Parser::AST unless parentobj.class == self.class error = Puppet::ParseError.new( "Class %s has incompatible parent type, %s vs %s" % - [@name, parentobj.class, self.class] + [@type, parentobj.class, self.class] ) error.file = self.file error.line = self.line raise error end - return parentobj.safeevaluate(scope,args,@parentclass,name) + # We don't need to pass the type, because the parent will just + # use its own type + return parentobj.safeevaluate( + :scope => scope, + :arguments => args, + :name => name + ) + else + return false end end |