blob: b8edff8f161eef68e84e5294711b05efc9fc1f1c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
require 'puppet/parser/ast/branch'
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
# Evaluate our object, but just return a simple array of the type
# and name.
def evaluate(hash)
scope = hash[:scope]
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
else
raise Puppet::ParseError, "Could not find resource type %s" % objtype
end
end
return objtype
end
end
end
|