# Copyright (c) 2002-2008 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: DomainName.pm,v 2.5 2008/05/31 21:58:18 nagler Exp $ package Bivio::Type::DomainName; use strict; use Bivio::Base 'Type.SyntacticString'; use Socket (); our($VERSION) = sprintf('%d.%02d', q$Revision: 2.5 $ =~ /\d+/g); sub REGEX { return qr/((?:[-a-z0-9]{1,63})(?:\.[-a-z0-9]{1,63})+)/is; } sub SYNTAX_ERROR { return Bivio::TypeError->DOMAIN_NAME; } sub get_width { return 255; } sub internal_post_from_literal { return lc($_[1]); } sub unsafe_to_dotted_decimal { my($proto, $value) = @_; return Socket::inet_ntoa( gethostbyname($proto->from_literal_or_die($value)) || return undef, ); } 1;