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