4 module Puppet::Parser::Functions
5 newfunction(:is_integer, :type => :rvalue, :doc => <<-DOC
7 **Deprecated:** Returns true if the variable passed to this function is an Integer or
8 a decimal (base 10) integer in String form.
10 The string may start with a '-' (minus). A value of '0' is allowed, but a leading '0'
11 digit may not be followed by other digits as this indicates that the value is octal (base 8).
13 If given any other argument `false` is returned.
16 Returns `true` or `false`
18 > **Note:* **Deprecated** Will be removed in a future version of stdlib. See
19 [`validate_legacy`](#validate_legacy).
23 function_deprecation([:is_integer, 'This method is deprecated, please use the stdlib validate_legacy function,
24 with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README.'])
26 if arguments.size != 1
27 raise(Puppet::ParseError, "is_integer(): Wrong number of arguments given #{arguments.size} for 1")
32 # Regex is taken from the lexer of puppet
33 # puppet/pops/parser/lexer.rb but modified to match also
34 # negative values and disallow numbers prefixed with multiple
37 # TODO these parameter should be a constant but I'm not sure
38 # if there is no risk to declare it inside of the module
39 # Puppet::Parser::Functions
41 # Integer numbers like
44 numeric = %r{^-?(?:(?:[1-9]\d*)|0)$}
46 return true if value.is_a?(Integer) || (value.is_a?(String) && value.match(numeric))
51 # vim: set ts=2 sw=2 et :