From 7c8ae311cade65e84df1054779a039ff906e630c Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 15 Dec 2014 16:11:10 -0800 Subject: (MODULES-1473) Deprecate type() function for new parser The `type()` function will cease to work on the new parser because 'type' is a reserved keyword. The `type3x()` function may be used to continue similar functionality, but will be deprecated in favor of the built-in typing system. The `type_of()` function has been included to introspect types in the new parser. --- lib/puppet/functions/type_of.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lib/puppet/functions/type_of.rb (limited to 'lib/puppet/functions/type_of.rb') diff --git a/lib/puppet/functions/type_of.rb b/lib/puppet/functions/type_of.rb new file mode 100644 index 0000000..02cdd4d --- /dev/null +++ b/lib/puppet/functions/type_of.rb @@ -0,0 +1,17 @@ +# Returns the type when passed a value. +# +# @example how to compare values' types +# # compare the types of two values +# if type_of($first_value) != type_of($second_value) { fail("first_value and second_value are different types") } +# @example how to compare against an abstract type +# unless type_of($first_value) <= Numeric { fail("first_value must be Numeric") } +# unless type_of{$first_value) <= Collection[1] { fail("first_value must be an Array or Hash, and contain at least one element") } +# +# See the documentation for "The Puppet Type System" for more information about types. +# See the `assert_type()` function for flexible ways to assert the type of a value. +# +Puppet::Functions.create_function(:type_of) do + def type_of(value) + Puppet::Pops::Types::TypeCalculator.infer_set(value) + end +end -- cgit v1.2.3