Class::Value::Net::Hostname - Network-related value objects


Class-Value-Net documentation Contained in the Class-Value-Net distribution.

Index


Code Index:

NAME

Top

Class::Value::Net::Hostname - Network-related value objects

VERSION

Top

version 1.110250

METHODS

Top

is_valid_normalized_value

FIXME

normalize_value

FIXME

send_notify_value_invalid

FIXME

INSTALLATION

Top

See perlmodinstall for information and options on installing Perl modules.

BUGS AND LIMITATIONS

Top

No bugs have been reported.

Please report any bugs or feature requests through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Class-Value-Net.

AVAILABILITY

Top

The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you, or see http://search.cpan.org/dist/Class-Value-Net/.

The development version lives at http://github.com/hanekomu/Class-Value-Net and may be cloned from git://github.com/hanekomu/Class-Value-Net.git. Instead of sending patches, please fork this project using the standard git and github infrastructure.

AUTHOR

Top

Marcel Gruenauer <marcel@cpan.org>

COPYRIGHT AND LICENSE

Top


Class-Value-Net documentation Contained in the Class-Value-Net distribution.

use 5.008;
use strict;
use warnings;

package Class::Value::Net::Hostname;
BEGIN {
  $Class::Value::Net::Hostname::VERSION = '1.110250';
}

# ABSTRACT: Network-related value objects
use parent 'Class::Value::Net';

# Hostnames can end with a dot; however it will be normalized away. E.g.,
# 'foo.at.' is valid, but will be normalized to 'foo.at'.
#
# An undef value will be normalized to the empty string.
sub normalize_value {
    my ($self, $value) = @_;
    return '' unless defined $value;
    $value =~ s/\.$//;
    $value;
}

sub is_valid_normalized_value {
    my ($self, $value) = @_;

    # hostname can be undef or the empty string
    return 1 unless defined $value and length $value;
    return 0 unless $self->SUPER::is_valid_normalized_value($value);
    our $label_re ||= qr/[0-9a-z]([0-9a-z-]{0,61}[0-9a-z])?/;
    return
         $value eq lc($value)
      && length($value) <= 255
      && $value =~ /^$label_re(\.$label_re)+$/
      && $value =~ /[a-z]/;
}

sub send_notify_value_invalid {
    my ($self, $value) = @_;
    local $Error::Depth = $Error::Depth + 2;
    $self->exception_container->record(
        'Class::Value::Net::Exception::MalformedHostname',
        hostname => $value,);
}
1;


__END__