NAME

NetObj::IPv4Address - represent a IPv4 address

VERSION

version 1.0

SYNOPSIS

  use NetObj::IPv4Address;

  # constructor
  my $ip1 = NetObj::IPv4Address->new('127.0.0.1');

  # convert to string
  $ip1->to_string(); # "127.0.0.1"
  "$ip1" ; # "127.0.0.1" by implicit stringification

  # comparison, numerically and stringwise
  my $ip2 = NetObj::IPv4Address->new('192.168.0.1');
  $ip1 == $ip1; # true
  $ip1 == $ip2; # false
  $ip1 != $ip2; # true
  $ip1 eq $ip1; # true
  $ip1 eq $ip2; # false
  $ip1 ne $ip2; # true

  # test for validity
  NetObj::IPv4Address::is_valid('127.0.0.1'); # true
  NetObj::IPv4Address::is_valid('1.2.3.4.5'); # false

  # construct from raw binary IPv4 address (4 bytes)
  my $ip2 = NetObj::IPv4Address->new("\x7f\x00\x00\x01"); # 127.0.0.1

DESCRIPTION

NetObj::IPv4Address represents IPv4 addresses.

NetObj::IPv4Address is implemented as a Moose style object class (using Moo).

METHODS

is_valid

The class method NetObj::IPv4Address::is_valid tests for the validity of a IPv4 address represented by a string. It does not throw an exception but returns false for an invalid and true for a valid IPv4 address.

If called on an object it does throw an exception.

new

The constructor expects exactly one argument representing an IPv4 address as a string in the usual form of 4 decimal numbers between 0 and 255 separated by dots.

Raw 4 byte IPv4 addresses are supported.

It throws an exception for invalid IPv4 addresses.

to_string

The method to_string returns the canonical string representation of the IPv4 address as dotted decimal octets.

Implicit stringification in string context is supported.

binary

The binary method returns the raw 4 bytes of the IPv4 address.

AUTHOR

Elmar S. Heeb <elmar@heebs.ch>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2015 by Elmar S. Heeb.

This is free software, licensed under:

  The GNU General Public License, Version 3, June 2007