1 # Emulate the is_numeric and validate_numeric functions
2 # The regex is what's currently used in is_numeric
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:
7 # ```class example($value) { validate_numeric($value, 10, 0) }```
12 # class example(Stdlib::Compat::Numeric $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}.")
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.
22 # This allows you to find all places where a consumers of your code call it with unexpected values.
23 type Stdlib::Compat::Numeric = Variant[Numeric, Pattern[/^-?(?:(?:[1-9]\d*)|0)(?:\.\d+)?(?:[eE]-?\d+)?$/], Array[Variant[Numeric, Pattern[/^-?(?:(?:[1-9]\d*)|0)(?:\.\d+)?(?:[eE]-?\d+)?$/]]]]