4 module Puppet::Parser::Functions
11 **DEPRECATED:** this function is deprecated, please use dig() instead.
14 Looks up into a complex structure of arrays and hashes and returns a value
15 or the default value if nothing was found.
17 Key can contain slashes to describe path components. The function will go down
18 the structure and try to extract the required value.
30 $value = try_get_value($data, 'a/b/2', 'not_found', '/')
36 2 -> array index starting with 0
38 not_found -> (optional) will be returned if there is no value or the path did not match. Defaults to nil.
39 / -> (optional) path delimiter. Defaults to '/'.
42 In addition to the required "key" argument, "try_get_value" accepts default
43 argument. It will be returned if no value was found or a path component is
44 missing. And the fourth argument can set a variable path separator.
47 warning('try_get_value() DEPRECATED: this function is deprecated, please use dig() instead.')
52 if !(data.is_a?(Hash) || data.is_a?(Array)) || path == ''
53 return default || data
56 separator = args[3] || '/'
57 path = path.split(separator).map { |key| (key =~ %r{^\d+$}) ? key.to_i : key }
58 function_dig([data, path, default])