summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-06 18:45:41 -0500
committerLuke Kanies <luke@madstop.com>2007-09-06 18:45:41 -0500
commit653c1514b613f27cb22d24b4bdd7b6c118047566 (patch)
tree54fadb5316bed0637e646c1e6f9ad09077416435 /lib/puppet/parser
parent40e3b372ec2a3b45a5254a85f9b808bf3450e316 (diff)
downloadpuppet-653c1514b613f27cb22d24b4bdd7b6c118047566.tar.gz
puppet-653c1514b613f27cb22d24b4bdd7b6c118047566.tar.xz
puppet-653c1514b613f27cb22d24b4bdd7b6c118047566.zip
Fixing #806. Resources correctly look up their fully qualified definition type, just like resource references do, which causes the resource and reference to again agree on the full name of a given defined type.
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/ast/resourcedef.rb10
-rw-r--r--lib/puppet/parser/ast/resourceref.rb40
-rw-r--r--lib/puppet/parser/resource/reference.rb2
3 files changed, 34 insertions, 18 deletions
diff --git a/lib/puppet/parser/ast/resourcedef.rb b/lib/puppet/parser/ast/resourcedef.rb
index 02eac2b7b..a432268f1 100644
--- a/lib/puppet/parser/ast/resourcedef.rb
+++ b/lib/puppet/parser/ast/resourcedef.rb
@@ -1,9 +1,9 @@
-require 'puppet/parser/ast/branch'
+require 'puppet/parser/ast/resourceref'
# Any normal puppet resource declaration. Can point to a definition or a
# builtin type.
class Puppet::Parser::AST
-class ResourceDef < AST::Branch
+class ResourceDef < AST::ResourceRef
attr_accessor :title, :type, :exported, :virtual
attr_reader :params
@@ -24,6 +24,8 @@ class ResourceDef < AST::Branch
objtitles = [objtitles]
end
+ objtype = qualified_type(scope)
+
# This is where our implicit iteration takes place; if someone
# passed an array as the name, then we act just like the called us
# many times.
@@ -37,7 +39,7 @@ class ResourceDef < AST::Branch
# is true. Argh, this was a very tough one to track down.
virt = self.virtual || scope.resource.virtual? || exp
obj = Puppet::Parser::Resource.new(
- :type => @type,
+ :type => objtype,
:title => objtitle,
:params => paramobjects,
:file => self.file,
@@ -49,7 +51,7 @@ class ResourceDef < AST::Branch
)
# And then store the resource in the compile.
- # XXX At some point, we need to switch all of this to return
+ # At some point, we need to switch all of this to return
# objects instead of storing them like this.
scope.compile.store_resource(scope, obj)
obj
diff --git a/lib/puppet/parser/ast/resourceref.rb b/lib/puppet/parser/ast/resourceref.rb
index 167417f13..02a19d88d 100644
--- a/lib/puppet/parser/ast/resourceref.rb
+++ b/lib/puppet/parser/ast/resourceref.rb
@@ -25,28 +25,42 @@ class Puppet::Parser::AST
def evaluate(hash)
scope = hash[:scope]
- # We want a lower-case type.
- objtype = @type.downcase
title = @title.safeevaluate(:scope => scope)
+ if @type == "class"
+ objtype = @type
+ title = qualified_class(scope, title)
+ else
+ objtype = qualified_type(scope)
+ end
+ return Puppet::Parser::Resource::Reference.new(
+ :type => objtype, :title => 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.findclass(title)
+ title = classobj.classname
+ 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.finddefine(objtype)
objtype = dtype.classname
- elsif objtype == "class"
- # Look up the full path to the class
- if classobj = scope.findclass(title)
- title = classobj.classname
- else
- raise Puppet::ParseError, "Could not find class %s" % title
- end
else
raise Puppet::ParseError, "Could not find resource type %s" % objtype
end
end
-
- return Puppet::Parser::Resource::Reference.new(
- :type => objtype, :title => title
- )
+ return objtype
end
end
end
diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/parser/resource/reference.rb
index 0bc732558..543ee7195 100644
--- a/lib/puppet/parser/resource/reference.rb
+++ b/lib/puppet/parser/resource/reference.rb
@@ -69,7 +69,7 @@ class Puppet::Parser::Resource::Reference
def to_s
unless defined? @namestring
- @namestring = "%s[%s]" % [type.capitalize, title]
+ @namestring = "%s[%s]" % [type.split("::").collect { |s| s.capitalize }.join("::"), title]
end
@namestring
end