]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/getvar.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / getvar.rb
1 module Puppet::Parser::Functions
2
3   newfunction(:getvar, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
4     Lookup a variable in a remote namespace.
5
6     For example:
7
8         $foo = getvar('site::data::foo')
9         # Equivalent to $foo = $site::data::foo
10
11     This is useful if the namespace itself is stored in a string:
12
13         $datalocation = 'site::data'
14         $bar = getvar("${datalocation}::bar")
15         # Equivalent to $bar = $site::data::bar
16     ENDHEREDOC
17
18     unless args.length == 1
19       raise Puppet::ParseError, ("getvar(): wrong number of arguments (#{args.length}; must be 1)")
20     end
21
22     begin
23       self.lookupvar("#{args[0]}")
24     rescue Puppet::ParseError # Eat the exception if strict_variables = true is set
25     end
26
27   end
28
29 end