summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/functions.rb28
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb
index 5f0930c6a..1174d7dad 100644
--- a/lib/puppet/parser/functions.rb
+++ b/lib/puppet/parser/functions.rb
@@ -151,14 +151,28 @@ module Functions
# Test whether a given class or definition is defined
newfunction(:defined, :type => :rvalue, :doc => "Determine whether a given
- type is defined, either as a native type or a defined type.") do |vals|
- # For some reason, it doesn't want me to return from here.
- if vals.detect do |val| Puppet::Type.type(val) or finddefine(val) or findclass(val) end
- true
- else
- false
+ type is defined, either as a native type or a defined type, or whether a resource has been
+ specified. If you are checking with a resource is defined, use the normal resource
+ reference syntax, e.g., ``File['/etc/passwd']``.") do |vals|
+ result = false
+ vals.each do |val|
+ case val
+ when String:
+ # For some reason, it doesn't want me to return from here.
+ if Puppet::Type.type(val) or finddefine(val) or findclass(val)
+ result = true
+ break
+ end
+ when Puppet::Parser::Resource::Reference:
+ if findresource(val.to_s)
+ result = true
+ break
+ end
+ else
+ raise ArgumentError, "Invalid argument of type %s to 'defined'" % val.class
+ end
end
-
+ result
end
newfunction(:fail, :doc => "Fail with a parse error.") do |vals|