5 module Puppet::Parser::Functions
6 newfunction(:enclose_ipv6, :type => :rvalue, :doc => <<-EOS
7 Takes an array of ip addresses and encloses the ipv6 addresses with square brackets.
13 rescuable_exceptions = [ ArgumentError ]
14 if defined?(IPAddr::InvalidAddressError)
15 rescuable_exceptions << IPAddr::InvalidAddressError
18 if (arguments.size != 1) then
19 raise(Puppet::ParseError, "enclose_ipv6(): Wrong number of arguments given #{arguments.size} for 1")
21 unless arguments[0].is_a?(String) or arguments[0].is_a?(Array) then
22 raise(Puppet::ParseError, "enclose_ipv6(): Wrong argument type given #{arguments[0].class} expected String or Array")
25 input = [arguments[0]].flatten.compact
32 rescue *rescuable_exceptions
33 raise(Puppet::ParseError, "enclose_ipv6(): Wrong argument given #{val} is not an ip address.")
35 val = "[#{ip.to_s}]" if ip.ipv6?