Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / is_ipv6_address.rb
1 #
2 # is_ipv6_address.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:is_ipv6_address, :type => :rvalue, :doc => <<-DOC
6     @summary
7       **Deprecated:** Returns true if the string passed to this function is a valid IPv6 address.
8
9     @return [Boolean]
10       Returns `true` or `false`
11
12     > **Note:* **Deprecated** Will be removed in a future version of stdlib. See
13     [`validate_legacy`](#validate_legacy).
14     DOC
15              ) do |arguments|
16
17     function_deprecation([:is_ipv6_address, 'This method is deprecated, please use the stdlib validate_legacy function,
18                             with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.'])
19
20     require 'ipaddr'
21
22     if arguments.size != 1
23       raise(Puppet::ParseError, "is_ipv6_address(): Wrong number of arguments given #{arguments.size} for 1")
24     end
25
26     begin
27       ip = IPAddr.new(arguments[0])
28     rescue ArgumentError
29       return false
30     end
31
32     return ip.ipv6?
33   end
34 end
35
36 # vim: set ts=2 sw=2 et :