source: other-projects/hathitrust/vagrant-hadoop-cluster/trunk/modules/stdlib/types/compat/integer.pp@ 30903

Last change on this file since 30903 was 30903, checked in by davidb, 7 years ago

Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details

File size: 1.2 KB
Line 
1# Emulate the is_integer and validate_integer functions
2# The regex is what's currently used in is_integer
3# validate_numeric also allows range checking, which cannot be mapped to the string parsing inside the function.
4# For full backwards compatibility, you will need to keep the validate_numeric call around to catch everything.
5# To keep your development moving forward, you can also add a deprecation warning using the Integer type:
6#
7# ```class example($value) { validate_integer($value, 10, 0) }```
8#
9# would turn into
10#
11# ```
12# class example(Stdlib::Compat::Integer $value) {
13# validate_numeric($value, 10, 0)
14# assert_type(Integer[0, 10], $value) |$expected, $actual| {
15# warning("The 'value' parameter for the 'ntp' class has type ${actual}, but should be ${expected}.")
16# }
17# }
18# ```
19#
20# > Note that you need to use Variant[Integer[0, 10], Float[0, 10]] if you want to match both integers and floating point numbers.
21#
22# This allows you to find all places where a consumers of your code call it with unexpected values.
23type Stdlib::Compat::Integer = Variant[Integer, Pattern[/^-?(?:(?:[1-9]\d*)|0)$/], Array[Variant[Integer, Pattern[/^-?(?:(?:[1-9]\d*)|0)$/]]]]
Note: See TracBrowser for help on using the repository browser.