summaryrefslogtreecommitdiff
path: root/types/compat/integer.pp
diff options
context:
space:
mode:
authorvarac <varacanero@zeromail.org>2017-01-13 12:41:58 +0100
committervarac <varacanero@zeromail.org>2017-01-13 12:41:58 +0100
commit066c08f8362d53f0f30897cb8710d11260c726ea (patch)
treea6369eecd88bb731fe413d0bbc8af73d74d1f447 /types/compat/integer.pp
parent71123634744b9fe2ec7d6a3e38e9789fd84801e3 (diff)
parentb65dd1f45d10e10e45455358aeabb29167990e2c (diff)
Merge remote-tracking branch 'origin/master' into leap_master
Diffstat (limited to 'types/compat/integer.pp')
-rw-r--r--types/compat/integer.pp23
1 files changed, 23 insertions, 0 deletions
diff --git a/types/compat/integer.pp b/types/compat/integer.pp
new file mode 100644
index 0000000..e5cadb6
--- /dev/null
+++ b/types/compat/integer.pp
@@ -0,0 +1,23 @@
+# Emulate the is_integer and validate_integer functions
+# The regex is what's currently used in is_integer
+# validate_numeric also allows range checking, which cannot be mapped to the string parsing inside the function.
+# For full backwards compatibility, you will need to keep the validate_numeric call around to catch everything.
+# To keep your development moving forward, you can also add a deprecation warning using the Integer type:
+#
+# ```class example($value) { validate_integer($value, 10, 0) }```
+#
+# would turn into
+#
+# ```
+# class example(Stdlib::Compat::Integer $value) {
+# validate_numeric($value, 10, 0)
+# assert_type(Integer[0, 10], $value) |$expected, $actual| {
+# warning("The 'value' parameter for the 'ntp' class has type ${actual}, but should be ${expected}.")
+# }
+# }
+# ```
+#
+# > Note that you need to use Variant[Integer[0, 10], Float[0, 10]] if you want to match both integers and floating point numbers.
+#
+# This allows you to find all places where a consumers of your code call it with unexpected values.
+type Stdlib::Compat::Integer = Variant[Integer, Pattern[/^-?(?:(?:[1-9]\d*)|0)$/], Array[Variant[Integer, Pattern[/^-?(?:(?:[1-9]\d*)|0)$/]]]]