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/classdef.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/classdef.rb')
-rw-r--r-- | lib/puppet/parser/ast/classdef.rb | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/lib/puppet/parser/ast/classdef.rb b/lib/puppet/parser/ast/classdef.rb index 147ab88e5..0a6a86816 100644 --- a/lib/puppet/parser/ast/classdef.rb +++ b/lib/puppet/parser/ast/classdef.rb @@ -9,36 +9,37 @@ class Puppet::Parser::AST def each if @parentclass - #[@name,@args,@parentclass,@code].each { |child| yield child } - [@name,@parentclass,@code].each { |child| yield child } + #[@type,@args,@parentclass,@code].each { |child| yield child } + [@type,@parentclass,@code].each { |child| yield child } else - #[@name,@args,@code].each { |child| yield child } - [@name,@code].each { |child| yield child } + #[@type,@args,@code].each { |child| yield child } + [@type,@code].each { |child| yield child } end end - # Store our parse tree according to name. - def evaluate(scope) - name = @name.safeevaluate(scope) - #args = @args.safeevaluate(scope) + # Store our parse tree according to type. + def evaluate(hash) + scope = hash[:scope] + type = @type.safeevaluate(:scope => scope) + #args = @args.safeevaluate(:scope => scope) #:args => args, arghash = { - :name => name, + :type => type, :code => @code } if @parentclass - arghash[:parentclass] = @parentclass.safeevaluate(scope) + arghash[:parentclass] = @parentclass.safeevaluate(:scope => scope) end #Puppet.debug("defining hostclass '%s' with arguments [%s]" % - # [name,args]) + # [type,args]) begin hclass = HostClass.new(arghash) hclass.keyword = self.keyword - scope.settype(name, hclass) + scope.settype(type, hclass) rescue Puppet::ParseError => except except.line = self.line except.file = self.file @@ -61,7 +62,7 @@ class Puppet::Parser::AST def tree(indent = 0) #@args.tree(indent + 1), return [ - @name.tree(indent + 1), + @type.tree(indent + 1), ((@@indline * 4 * indent) + self.typewrap("class")), @parentclass ? @parentclass.tree(indent + 1) : "", @code.tree(indent + 1), @@ -70,8 +71,8 @@ class Puppet::Parser::AST def to_s return "class %s(%s) inherits %s {\n%s }" % - [@name, @parentclass, @code] - #[@name, @args, @parentclass, @code] + [@type, @parentclass, @code] + #[@type, @args, @parentclass, @code] end end |