Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on Net::IP, and use Net::IP::XS everywhere #1119

Merged
merged 10 commits into from
Sep 16, 2022
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ RUN apk add --no-cache \
perl-lwp-protocol-https \
perl-module-install \
perl-moose \
perl-net-ip \
anandb-ripencc marked this conversation as resolved.
Show resolved Hide resolved
perl-pod-coverage \
perl-test-differences \
perl-test-exception \
Expand All @@ -28,7 +27,8 @@ RUN apk add --no-cache \
Email::Valid \
Locale::TextDomain \
Module::Find \
MooseX::Singleton
MooseX::Singleton \
Net::IP::XS

ARG version

Expand Down
4 changes: 1 addition & 3 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ requires 'Locale::TextDomain' => 1.20;
requires 'Module::Find' => 0.10;
requires 'Moose' => 2.0401;
requires 'MooseX::Singleton' => 0.30;
requires 'Net::IP' => 1.26;
requires 'Net::IP::XS' => 0.21;
requires 'Readonly' => 0;
requires 'Text::CSV' => 0;
requires 'Zonemaster::LDNS' => 2.002002;
Expand All @@ -46,8 +46,6 @@ if ($^O eq "freebsd") {
requires_external_bin 'gmake';
};

recommends 'Net::IP::XS' => 0;

sub MY::postamble {
my $pure_all;
if ($^O eq "freebsd") {
Expand Down
4 changes: 2 additions & 2 deletions lib/Zonemaster/Engine/ASNLookup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ Zonemaster::Engine::ASNLookup - do lookups of ASNs for IP addresses

=item get($addr)

Takes a string (or a L<Net::IP> object) with a single IP address, does a lookup
Takes a string (or a L<Net::IP::XS> object) with a single IP address, does a lookup
in a Cymru-style DNS zone and returns a list of AS numbers for the address, if
any can be found.

=item get_with_prefix($addr)

As L<get()>, except it returns a list of a reference to a list with the AS
numbers, and a Net::IP object representing the prefix of the AS.
numbers, and a Net::IP::XS object representing the prefix of the AS.

=back

Expand Down
40 changes: 6 additions & 34 deletions lib/Zonemaster/Engine/Net/IP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,8 @@ use version; our $VERSION = version->declare("v0.0.6");

use strict;
use warnings;

my $p_class = eval {
require Net::IP::XS;
return q{Net::IP::XS};
} || eval {
require Net::IP;
return q{Net::IP};
};

if ( $p_class ) {
$p_class->import;
}
else {
die "Both Net::IP and Net::IP::XS missing?\n";
}
use Net::IP::XS;
my $p_class = q{Net::IP::XS};

sub new {
my ( $class, @args ) = @_;
Expand Down Expand Up @@ -70,37 +57,22 @@ sub version {
}

sub ip_is_ipv4 {
if ( $p_class eq 'Net::IP::XS' ) {
return Net::IP::XS::ip_is_ipv4( @_ );
}
else {
return Net::IP::ip_is_ipv4( @_ );
}
return Net::IP::XS::ip_is_ipv4( @_ );
}

sub ip_is_ipv6 {
if ( $p_class eq 'Net::IP::XS' ) {
return Net::IP::XS::ip_is_ipv6( @_ );
}
else {
return Net::IP::ip_is_ipv6( @_ );
}
return Net::IP::XS::ip_is_ipv6( @_ );
}

sub Error {
if ( $p_class eq 'Net::IP::XS' ) {
return Net::IP::XS::Error();
}
else {
return Net::IP::Error();
}
return Net::IP::XS::Error();
}

1;

=head1 NAME

Zonemaster::Engine::Net::IP - Net::IP/Net::IP::XS Wrapper (STILL EXPERIMENTAL)
Zonemaster::Engine::Net::IP - Net::IP::XS Wrapper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably mark this module as deprecated in this release. In a future release we can drop it entirely and just use Net::IP::XS directly instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably mark this module as deprecated in this release. In a future release we can drop it entirely and just use Net::IP::XS directly instead.

If Net::IP is not dropped then #1108 should be merged to work-around the bug in Net::IP.


=head1 SYNOPSIS

Expand Down
4 changes: 2 additions & 2 deletions lib/Zonemaster/Engine/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Moose;

use Readonly;
use Module::Find;
use Net::IP;
use Net::IP::XS;
use List::MoreUtils;
use Clone;

Expand Down Expand Up @@ -48,7 +48,7 @@ sub _log_versions {
info( DEPENDENCY_VERSION => { name => 'Module::Find', version => $Module::Find::VERSION } );
info( DEPENDENCY_VERSION => { name => 'File::ShareDir', version => $File::ShareDir::VERSION } );
info( DEPENDENCY_VERSION => { name => 'File::Slurp', version => $File::Slurp::VERSION } );
info( DEPENDENCY_VERSION => { name => 'Net::IP', version => $Net::IP::VERSION } );
info( DEPENDENCY_VERSION => { name => 'Net::IP::XS', version => $Net::IP::XS::VERSION } );
info( DEPENDENCY_VERSION => { name => 'List::MoreUtils', version => $List::MoreUtils::VERSION } );
info( DEPENDENCY_VERSION => { name => 'Clone', version => $Clone::VERSION } );
info( DEPENDENCY_VERSION => { name => 'Readonly', version => $Readonly::VERSION } );
Expand Down