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