4 module Puppet::Parser::Functions
5 newfunction(:validate_string, :doc => <<-DOC
7 Validate that all passed values are string data structures
10 Validate that all passed values are string data structures. Failed
11 compilation if any value fails this check.
14 The following values will pass:
16 $my_string = "one two"
17 validate_string($my_string, 'three')
19 The following values will fail, causing compilation to abort:
22 validate_string([ 'some', 'array' ])
24 Validate_string(undef) will not fail in this version of the
25 functions API (incl. current and future parser). Instead, use:
33 function_deprecation([:validate_string, 'This method is deprecated, please use the stdlib validate_legacy function,
34 with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.'])
37 raise Puppet::ParseError, "validate_string(): wrong number of arguments (#{args.length}; must be > 0)"
41 # when called through the v4 API shim, undef gets translated to nil
42 unless arg.is_a?(String) || arg.nil?
43 raise Puppet::ParseError, "#{arg.inspect} is not a string. It looks to be a #{arg.class}"