summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/ast/definition.rb11
-rw-r--r--lib/puppet/parser/ast/node.rb2
-rw-r--r--lib/puppet/parser/compile.rb14
-rw-r--r--lib/puppet/parser/functions.rb4
-rw-r--r--lib/puppet/parser/resource.rb34
-rw-r--r--lib/puppet/parser/scope.rb38
6 files changed, 38 insertions, 65 deletions
diff --git a/lib/puppet/parser/ast/definition.rb b/lib/puppet/parser/ast/definition.rb
index 9ad1f539d..1cdaa6431 100644
--- a/lib/puppet/parser/ast/definition.rb
+++ b/lib/puppet/parser/ast/definition.rb
@@ -37,12 +37,12 @@ class Puppet::Parser::AST
# Additionally, add a tag for whatever kind of class
# we are
if @classname != "" and ! @classname.nil?
- @classname.split(/::/).each { |tag| scope.tag(tag) }
+ @classname.split(/::/).each { |tag| scope.resource.tag(tag) }
end
[resource.name, resource.title].each do |str|
unless str.nil? or str =~ /[^\w]/ or str == ""
- scope.tag(str)
+ scope.resource.tag(str)
end
end
@@ -123,10 +123,7 @@ class Puppet::Parser::AST
end
# Create a new subscope in which to evaluate our code.
- def subscope(scope, resource = nil)
- unless resource
- raise ArgumentError, "Resources are required when creating subscopes"
- end
+ def subscope(scope, resource)
args = {
:resource => resource,
:keyword => self.keyword,
@@ -192,7 +189,7 @@ class Puppet::Parser::AST
# [default.inspect, arg.inspect, @name.inspect]
else
parsefail "Must pass %s to %s of type %s" %
- [arg,title,@classname]
+ [arg, resource.title, @classname]
end
end
}
diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb
index 20c03f4ce..a296e43ba 100644
--- a/lib/puppet/parser/ast/node.rb
+++ b/lib/puppet/parser/ast/node.rb
@@ -19,7 +19,7 @@ class Puppet::Parser::AST
# We don't have to worry about the declarativeness of node parentage,
# because the entry point is always a single node definition.
if parent = self.parentobj
- scope = parent.safeevaluate :scope => scope
+ scope = parent.safeevaluate :scope => scope, :resource => options[:resource]
end
scope = scope.newscope(
diff --git a/lib/puppet/parser/compile.rb b/lib/puppet/parser/compile.rb
index a8e80eb9d..841e58d4d 100644
--- a/lib/puppet/parser/compile.rb
+++ b/lib/puppet/parser/compile.rb
@@ -14,7 +14,7 @@ require 'puppet/util/errors'
class Puppet::Parser::Compile
include Puppet::Util
include Puppet::Util::Errors
- attr_reader :topscope, :parser, :node, :facts, :collections
+ attr_reader :topscope, :parser, :node, :facts, :collections, :configuration
attr_writer :ast_nodes
@@ -121,13 +121,14 @@ class Puppet::Parser::Compile
classes.each do |name|
# If we can find the class, then make a resource that will evaluate it.
if klass = scope.findclass(name)
- # Create a resource to model this class, and then add it to the list
- # of resources.
unless scope.source
- raise "No source for %s" % scope.to_s
+ raise Puppet::DevError, "No source for %s" % scope.to_s
end
+ # Create a resource to model this class, and then add it to the list
+ # of resources.
resource = Puppet::Parser::Resource.new(:type => "class", :title => klass.classname, :scope => scope, :source => scope.source)
store_resource(scope, resource)
+ @configuration.tag(klass.classname)
found << name
else
Puppet.info "Could not find class %s for %s" % [name, node.name]
@@ -311,11 +312,6 @@ class Puppet::Parser::Compile
@configuration.add_vertex!(@main_resource)
@resource_table["Class[main]"] = @main_resource
- #if klass = @parser.findclass("", "")
- # # Set the source, so objects can tell where they were defined.
- # topscope.source = klass
- # klass.safeevaluate :scope => topscope, :nosubscope => true
- #end
end
# Make sure the entire configuration is evaluated.
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb
index cbb7f4e2d..4c747af84 100644
--- a/lib/puppet/parser/functions.rb
+++ b/lib/puppet/parser/functions.rb
@@ -135,7 +135,7 @@ module Functions
newfunction(:tag, :doc => "Add the specified tags to the containing class
or definition. All contained objects will then acquire that tag, also.
") do |vals|
- self.tag(*vals)
+ self.resource.tag(*vals)
end
# Test whether a given tag is set. This functions as a big OR -- if any of the
@@ -148,7 +148,7 @@ module Functions
retval = true
vals.each do |val|
- unless classlist.include?(val) or self.tags.include?(val)
+ unless classlist.include?(val) or self.resource.tags.include?(val)
retval = false
break
end
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 3f5ca78ae..a8da6b054 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -90,11 +90,10 @@ class Puppet::Parser::Resource
end
end
- [:scope, :source].each do |attribute|
- unless self.send(attribute)
- raise ArgumentError, "Resources require a %s" % attribute
- end
+ unless self.scope
+ raise ArgumentError, "Resources require a scope"
end
+ @source ||= scope.source
options = symbolize_options(options)
@@ -122,6 +121,13 @@ class Puppet::Parser::Resource
unless options.empty?
raise ArgumentError, "Resources do not accept %s" % options.keys.collect { |k| k.to_s }.join(", ")
end
+
+ @tags = []
+ @tags << @ref.type.to_s
+ @tags << @ref.title.to_s if @ref.title.to_s =~ /^[-\w]+$/
+ if scope.resource
+ @tags += scope.resource.tags
+ end
end
# Merge an override resource in. This will throw exceptions if
@@ -208,12 +214,22 @@ class Puppet::Parser::Resource
@ref.to_s
end
+ # Add a tag to our current list. These tags will be added to all
+ # of the objects contained in this scope.
+ def tag(*ary)
+ ary.each { |tag|
+ tag = tag.to_s
+ unless tag =~ /^\w[-\w]*$/
+ fail Puppet::ParseError, "Invalid tag %s" % tag.inspect
+ end
+ unless @tags.include?(tag)
+ @tags << tag
+ end
+ }
+ end
+
def tags
- unless defined? @tags
- @tags = scope.tags
- @tags << self.type unless @tags.include?(self.type)
- end
- @tags
+ @tags.dup
end
def to_hash
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 4516715e1..028414cc0 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -311,47 +311,11 @@ class Puppet::Parser::Scope
return out
end
- # Add a tag to our current list. These tags will be added to all
- # of the objects contained in this scope.
- def tag(*ary)
- ary.each { |tag|
- if tag.nil? or tag == ""
- puts caller
- Puppet.debug "got told to tag with %s" % tag.inspect
- next
- end
- unless tag =~ /^\w[-\w]*$/
- fail Puppet::ParseError, "Invalid tag %s" % tag.inspect
- end
- tag = tag.to_s
- unless @tags.include?(tag)
- #Puppet.info "Tagging scope %s with %s" % [self.object_id, tag]
- @tags << tag
- end
- }
- end
-
# Return the tags associated with this scope. It's basically
# just our parents' tags, plus our type. We don't cache this value
# because our parent tags might change between calls.
def tags
- tmp = [] + @tags
- unless ! defined? @type or @type.nil? or @type == ""
- tmp << @type.to_s
- end
- if parent
- #info "Looking for tags in %s" % parent.type
- parent.tags.each { |tag|
- if tag.nil? or tag == ""
- Puppet.debug "parent returned tag %s" % tag.inspect
- next
- end
- unless tmp.include?(tag)
- tmp << tag
- end
- }
- end
- return tmp.sort.uniq
+ resource.tags
end
# Used mainly for logging