Net::CIDR::Overlap - A utility module for helping make sure a list of CIDRs don't overlap.
Version 0.0.1
my $nco=Net::CIDR::Overlap->new; # add some subnets eval{ $nco->add( '127.0.0.0/24' ); $nco->add( '192.168.42.0/24' ); $nco->add( '10.10.0.0/16' ); } if ( $@ ){ warn( $@ ); } # this will fail as they have already been added eval{ $nco->add( '127.0.0.0/25' ); $nco->add( '10.10.10/24' ); } if ( $@ ){ warn( $@ ); } # this will fail this is not a valid CIDR eval{ $nco->add( 'foo' ); } if ( $@ ){ warn( $@ ); } # print the subnets we added with out issue my $list=$nco->list; foreach my $cidr ( @${ $list } ){ print $cidr."\n"; }
This initates the object.
No arguments are taken.
This will always succeeed.
my $nco=Net::CIDR::Overlap->new;
This adds a subnet to the set being checked.
Net::CIDR::cidrvalidate is used to validate passed CIDR/IP.
This will die if it is called with a undef value of if validation fails.
This does not check if what is being added overlaps with anything already added.
eval{ $nco->add( $cidr ); } if ( $@ ){ warn( $@ ); }
This first checks for overlap and then adds it.
There is one required argument and two optional.
The first and required is the CIDR/IP. This will be validated using Net::CIDR::cidrvalidate.
The second is if to invert the check or not. If set to true, it will only be added if overlap is found.
The third is if overlap should be any or all. This is boolean and a value of true sets it to all. The default value is false, meaning any overlap.
# just add it if there is no overlap eval{ $nco->compare_and_add( $cidr ); } if ( $@ ){ warn( $@ ); } # this time invert it and use use any for the overlap check eval{ $nco->add( $cidr, '1', '0' ); } if ( $@ ){ warn( $@ ); }
This returns a array ref of successfully added items.
my $list=$nco->list; foreach my $cidr ( @${ $list } ){ print $cidr."\n"; }
Zane C. Bowers-Hadley, <vvelox at vvelox.net>
<vvelox at vvelox.net>
Please report any bugs or feature requests to bug-net-cidr-overlap at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-CIDR-Overlap. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-net-cidr-overlap at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Net::CIDR::Overlap
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-CIDR-Overlap
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Net-CIDR-Overlap
CPAN Ratings
https://cpanratings.perl.org/d/Net-CIDR-Overlap
Search CPAN
https://metacpan.org/release/Net-CIDR-Overlap
This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Net::CIDR::Overlap, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::CIDR::Overlap
CPAN shell
perl -MCPAN -e shell install Net::CIDR::Overlap
For more information on module installation, please visit the detailed CPAN module installation guide.