NetObj::IPv4Address - represent a IPv4 address
version 1.0
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
NetObj::IPv4Address represents IPv4 addresses.
NetObj::IPv4Address is implemented as a Moose style object class (using Moo).
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.
NetObj::IPv4Address::is_valid
If called on an object it does throw an exception.
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.
The method to_string returns the canonical string representation of the IPv4 address as dotted decimal octets.
to_string
Implicit stringification in string context is supported.
The binary method returns the raw 4 bytes of the IPv4 address.
binary
Elmar S. Heeb <elmar@heebs.ch>
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
To install NetObj::IPv4Address, copy and paste the appropriate command in to your terminal.
cpanm
cpanm NetObj::IPv4Address
CPAN shell
perl -MCPAN -e shell install NetObj::IPv4Address
For more information on module installation, please visit the detailed CPAN module installation guide.