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/component.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/component.rb')
-rw-r--r-- | lib/puppet/parser/ast/component.rb | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/lib/puppet/parser/ast/component.rb b/lib/puppet/parser/ast/component.rb index 858ef86f6..aa29624fd 100644 --- a/lib/puppet/parser/ast/component.rb +++ b/lib/puppet/parser/ast/component.rb @@ -10,20 +10,35 @@ class Puppet::Parser::AST # The class name @name = :component - attr_accessor :name, :args, :code, :scope, :autoname, :keyword - - def evaluate(scope,hash,objtype,objname) - scope = scope.newscope + attr_accessor :type, :args, :code, :scope, :autoname, :keyword + + #def evaluate(scope,hash,objtype,objname) + def evaluate(hash) + scope = hash[:scope] + objtype = hash[:type] + objname = hash[:name] + arguments = hash[:arguments] || {} + + scope = scope.newscope( + :type => @type, + :name => objname, + :keyword => self.keyword, + :autoname => self.autoname + ) + if hash[:newcontext] + #scope.warning "Setting context to %s" % self.object_id + scope.context = self.object_id + end @scope = scope # The type is the component or class name - scope.type = objtype + #scope.type = objtype # The name is the name the user has chosen or that has # been dynamically generated. This is almost never used - scope.name = objname + #scope.name = objname - scope.keyword = self.keyword + #scope.keyword = self.keyword # Retain the fact that we were autonamed, if so if self.autoname @@ -36,9 +51,10 @@ class Puppet::Parser::AST # Additionally, add a tag for whatever kind of class # we are - scope.tag(objtype) + scope.tag(@type) - unless objname =~ /-\d+/ # it was generated + unless objname.nil? + #Puppet.info "tagging with %s" % objname.inspect scope.tag(objname) end #scope.base = self.class.name @@ -46,21 +62,20 @@ class Puppet::Parser::AST # define all of the arguments in our local scope if self.args - # Verify that all required arguments are either present or # have been provided with defaults. # FIXME This should probably also require each parent # class's arguments... self.args.each { |arg, default| - unless hash.include?(arg) + unless arguments.include?(arg) if defined? default and ! default.nil? - hash[arg] = default + arguments[arg] = default #Puppet.debug "Got default %s for %s in %s" % # [default.inspect, arg.inspect, objname.inspect] else error = Puppet::ParseError.new( "Must pass %s to %s of type %s" % - [arg.inspect,name,objtype] + [arg.inspect,objname,@type] ) error.line = self.line error.file = self.file @@ -72,10 +87,10 @@ class Puppet::Parser::AST # Set each of the provided arguments as variables in the # component's scope. - hash["name"] = objname - hash.each { |arg,value| + arguments["name"] = objname + arguments.each { |arg,value| begin - scope.setvar(arg,hash[arg]) + scope.setvar(arg,arguments[arg]) rescue Puppet::ParseError => except except.line = self.line except.file = self.file @@ -94,7 +109,7 @@ class Puppet::Parser::AST } # Now just evaluate the code with our new bindings. - self.code.safeevaluate(scope) + self.code.safeevaluate(:scope => scope) # We return the scope, so that our children can make their scopes # under ours. This allows them to find our definitions. @@ -120,7 +135,7 @@ class Puppet::Parser::AST if found # It's a valid arg for us return true - elsif @parentclass + elsif defined? @parentclass and @parentclass # Else, check any existing parent parent = @scope.lookuptype(@parentclass) if parent and parent != [] |