Data-Semantic-Net

 view release on metacpan or  search on metacpan

lib/Data/Semantic/Net/IPAddress/IPv4.pm  view on Meta::CPAN


sub is_internal {
    my ($self, $value) = @_;
    return unless defined $value;

    # Net::IP::ip_iptype needs the IP in binary, although this is not
    # documented.
    my $type = ip_iptype(ip_iptobin($value, 4), 4) || 'PUBLIC';
    $type ne 'PUBLIC';
}

sub normalize {
    my ($self, $value) = @_;
    return undef unless (my @dummy = split(/\./, $value)) == 4;
    # omit leading zeroes in octets, e.g., 213.160.065.064 -> 213.160.65.64
    my $ip = Net::IP->new($value) or die Net::IP::Error();
    $ip->ip;
}

1;


__END__
=pod

=head1 NAME

Data::Semantic::Net::IPAddress::IPv4 - Semantic data class for IPv4 addresses

=head1 VERSION

version 1.101760

=head1 SYNOPSIS

    my $obj = Data::Semantic::Net::IPAddress::IPv4->new;
    if ($obj->is_valid('...')) {
        # ...
    }

=head1 DESCRIPTION

This class can tell whether a value is an IPv4 address. The C<valid()> method
will respect the inherited C<forbid_internal> boolean attribute.

=head1 METHODS

=head2 is_internal

Takes a value and returns true if the indicated IPv4 address is an internal
address, for example, C<10.0.1.1>, C<127.0.0.1> or C<192.168.1.3>.

=head2 is_valid_normalized_value

FIXME

=head1 INSTALLATION

See perlmodinstall for information and options on installing Perl modules.

=head1 BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests through the web interface at
L<http://rt.cpan.org>.

=head1 AVAILABILITY

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

The development version lives at
L<http://github.com/hanekomu/Data-Semantic-Net/>.
Instead of sending patches, please fork this project using the standard git
and github infrastructure.

=head1 AUTHOR

  Marcel Gruenauer <marcel@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2007 by Marcel Gruenauer.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut



( run in 0.602 second using v1.01-cache-2.11-cpan-39bf76dae61 )