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 if (arguments.size != 1) then
17 raise(Puppet::ParseError, "is_integer(): Wrong number of arguments "+
18 "given #{arguments.size} for 1")
23 # Regex is taken from the lexer of puppet
24 # puppet/pops/parser/lexer.rb but modified to match also
25 # negative values and disallow numbers prefixed with multiple
28 # TODO these parameter should be a constant but I'm not sure
29 # if there is no risk to declare it inside of the module
30 # Puppet::Parser::Functions
32 # Integer numbers like
35 numeric = %r{^-?(?:(?:[1-9]\d*)|0)$}
37 if value.is_a? Integer or (value.is_a? String and value.match numeric)
45 # vim: set ts=2 sw=2 et :