summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2010-01-29 20:57:21 -0600
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit7089446697ad550c22012bc2b5572030727d67e1 (patch)
tree40d160f11839fe6e20311186ded4e621d23e1242 /lib/puppet/parser/ast
parent4871c909cd28c82b64d0b62d8a27e62737d8733d (diff)
downloadpuppet-7089446697ad550c22012bc2b5572030727d67e1.tar.gz
puppet-7089446697ad550c22012bc2b5572030727d67e1.tar.xz
puppet-7089446697ad550c22012bc2b5572030727d67e1.zip
Removing Resource::Reference classes
This commit is hopefully less messy than it first appears, but it's certainly cross-cutting. The reason for all of this is that we previously only looked up builtin resource types from outside the parser, but now that the defined resource types are available globally via environments, we can push that lookup code to Resource. Once we do that, however, we have to have environment and namespace information in every resource. Here I remove the Resource::Reference classes (except the AST class), and use Resource instances instead. I did this because the shared code between the two classes got incredibly complicated, such that they should have had a hierarchical relationship disallowed by their constants. This complexity convinced me just to get rid of References entirely. I also make Puppet::Parser::Resource a subclass of Puppet::Resource. There are still broken tests in test/, but this was a big enough commit I wanted to get it in. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'lib/puppet/parser/ast')
-rw-r--r--lib/puppet/parser/ast/resource.rb8
-rw-r--r--lib/puppet/parser/ast/resource_defaults.rb2
-rw-r--r--lib/puppet/parser/ast/resource_override.rb4
-rw-r--r--lib/puppet/parser/ast/resource_reference.rb85
4 files changed, 20 insertions, 79 deletions
diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index d222893b3..5da40b32f 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -14,7 +14,7 @@ class Resource < AST::ResourceReference
# in the current scope.
def evaluate(scope)
# Evaluate all of the specified params.
- paramobjects = @params.collect { |param|
+ paramobjects = params.collect { |param|
param.safeevaluate(scope)
}
@@ -25,8 +25,6 @@ class Resource < AST::ResourceReference
resource_titles = [resource_titles]
end
- resource_type = qualified_type(scope)
-
# We want virtual to be true if exported is true. We can't
# just set :virtual => self.virtual in the initialization,
# because sometimes the :virtual attribute is set *after*
@@ -39,9 +37,7 @@ class Resource < AST::ResourceReference
# many times.
resource_titles.flatten.collect { |resource_title|
exceptwrap :type => Puppet::ParseError do
- resource = Puppet::Parser::Resource.new(
- :type => resource_type,
- :title => resource_title,
+ resource = Puppet::Parser::Resource.new(type, resource_title,
:params => paramobjects,
:file => self.file,
:line => self.line,
diff --git a/lib/puppet/parser/ast/resource_defaults.rb b/lib/puppet/parser/ast/resource_defaults.rb
index 3fde7ade2..f0746ecf1 100644
--- a/lib/puppet/parser/ast/resource_defaults.rb
+++ b/lib/puppet/parser/ast/resource_defaults.rb
@@ -12,7 +12,7 @@ class Puppet::Parser::AST
# object type.
def evaluate(scope)
# Use a resource reference to canonize the type
- ref = Puppet::Resource::Reference.new(@type, "whatever")
+ ref = Puppet::Resource.new(@type, "whatever")
type = ref.type
params = @params.safeevaluate(scope)
diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb
index 5eac50982..2d4f7a871 100644
--- a/lib/puppet/parser/ast/resource_override.rb
+++ b/lib/puppet/parser/ast/resource_override.rb
@@ -36,9 +36,7 @@ class Puppet::Parser::AST
resource = [resource] unless resource.is_a?(Array)
resource = resource.collect do |r|
- res = Puppet::Parser::Resource.new(
- :type => r.type,
- :title => r.title,
+ res = Puppet::Parser::Resource.new(r.type, r.title,
:params => params,
:file => file,
:line => line,
diff --git a/lib/puppet/parser/ast/resource_reference.rb b/lib/puppet/parser/ast/resource_reference.rb
index 794e505b8..8e09a8e3b 100644
--- a/lib/puppet/parser/ast/resource_reference.rb
+++ b/lib/puppet/parser/ast/resource_reference.rb
@@ -1,76 +1,23 @@
+require 'puppet/parser/ast'
require 'puppet/parser/ast/branch'
+require 'puppet/resource'
-class Puppet::Parser::AST
- # A reference to an object. Only valid as an rvalue.
- class ResourceReference < AST::Branch
- attr_accessor :title, :type
- # Is the type a builtin type?
- def builtintype?(type)
- if typeklass = Puppet::Type.type(type)
- return typeklass
- else
- return false
- end
- end
-
- def each
- [@type,@title].flatten.each { |param|
- #Puppet.debug("yielding param %s" % param)
- yield param
- }
- end
+class Puppet::Parser::AST::ResourceReference < Puppet::Parser::AST::Branch
+ attr_accessor :title, :type
- # Evaluate our object, but just return a simple array of the type
- # and name.
- def evaluate(scope)
- title = @title.safeevaluate(scope)
- title = [title] unless title.is_a?(Array)
-
- if @type.to_s.downcase == "class"
- resource_type = "class"
- title = title.collect { |t| qualified_class(scope, t) }
- else
- resource_type = qualified_type(scope)
- end
-
- title = title.collect { |t| Puppet::Parser::Resource::Reference.new(
- :type => resource_type, :title => t
- ) }
- return title.pop if title.length == 1
- return title
- end
-
- # Look up a fully qualified class name.
- def qualified_class(scope, title)
- # Look up the full path to the class
- if classobj = scope.find_hostclass(title)
- title = classobj.name
- else
- raise Puppet::ParseError, "Could not find class %s" % title
- end
- end
-
- # Look up a fully-qualified type. This method is
- # also used in AST::Resource.
- def qualified_type(scope, title = nil)
- # We want a lower-case type. For some reason.
- objtype = @type.downcase
- unless builtintype?(objtype)
- if dtype = scope.find_definition(objtype)
- objtype = dtype.name
- else
- raise Puppet::ParseError, "Could not find resource type %s" % objtype
- end
- end
- return objtype
- end
+ # Evaluate our object, but just return a simple array of the type
+ # and name.
+ def evaluate(scope)
+ titles = Array(title.safeevaluate(scope)).collect { |t| Puppet::Resource.new(type, t, :namespaces => scope.namespaces) }
+ return titles.pop if titles.length == 1
+ return titles
+ end
- def to_s
- if title.is_a?(ASTArray)
- "#{type.to_s.capitalize}#{title}"
- else
- "#{type.to_s.capitalize}[#{title}]"
- end
+ def to_s
+ if title.is_a?(Puppet::Parser::AST::ASTArray)
+ "#{type.to_s.capitalize}#{title}"
+ else
+ "#{type.to_s.capitalize}[#{title}]"
end
end
end