Net-Works-0.22/0000775000175000017500000000000012756362344013144 5ustar autarchautarchNet-Works-0.22/dist.ini0000644000175000017500000000065712756362344014616 0ustar autarchautarchname = Net-Works author = Dave Rolsky author = Greg Oschwald author = Olaf Alders license = Perl_5 copyright_holder = MaxMind, Inc. [@MAXMIND] dist = Net-Works pod_coverage_class = Pod::Coverage::Moose pod_coverage_skip = Net::Works::Role::IP pod_coverage_skip = Net::Works::Types pod_coverage_skip = Net::Works::Types::Internal stopwords_file = .stopwords Net-Works-0.22/perltidyrc0000644000175000017500000000033012756362344015242 0ustar autarchautarch--blank-lines-before-packages=0 --iterations=2 --no-outdent-long-comments -b -bar -boc -ci=4 -i=4 -l=78 -nolq -se -wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x=" Net-Works-0.22/cpanfile0000644000175000017500000000304112756362344014644 0ustar autarchautarchrequires "Carp" => "0"; requires "Exporter" => "0"; requires "List::AllUtils" => "0"; requires "Math::Int128" => "0.06"; requires "Moo" => "0"; requires "Moo::Role" => "0"; requires "Scalar::Util" => "0"; requires "Socket" => "1.99"; requires "Sub::Quote" => "0"; requires "integer" => "0"; requires "namespace::autoclean" => "0.16"; requires "overload" => "0"; requires "perl" => "5.010"; requires "strict" => "0"; requires "warnings" => "0"; on 'test' => sub { requires "B" => "0"; requires "ExtUtils::MakeMaker" => "0"; requires "File::Spec" => "0"; requires "Math::BigInt" => "0"; requires "Test::Fatal" => "0"; requires "Test::More" => "0.96"; requires "perl" => "5.010"; }; on 'test' => sub { recommends "CPAN::Meta" => "2.120900"; }; on 'configure' => sub { requires "ExtUtils::MakeMaker" => "0"; requires "perl" => "5.010000"; }; on 'develop' => sub { requires "File::Spec" => "0"; requires "IO::Handle" => "0"; requires "IPC::Open3" => "0"; requires "Perl::Critic" => "1.123"; requires "Perl::Tidy" => "20140711"; requires "Pod::Coverage::Moose" => "0"; requires "Pod::Coverage::TrustPod" => "0"; requires "Test::CPAN::Changes" => "0.19"; requires "Test::Code::TidyAll" => "0.24"; requires "Test::EOL" => "0"; requires "Test::More" => "0.88"; requires "Test::NoTabs" => "0"; requires "Test::Pod" => "1.41"; requires "Test::Pod::Coverage" => "1.08"; requires "Test::Portability::Files" => "0"; requires "Test::Spelling" => "0.12"; requires "Test::Synopsis" => "0"; requires "Test::Version" => "1"; }; Net-Works-0.22/t/0000775000175000017500000000000012756362344013407 5ustar autarchautarchNet-Works-0.22/t/author-test-version.t0000644000175000017500000000103712756362344017535 0ustar autarchautarch BEGIN { unless ($ENV{AUTHOR_TESTING}) { print "1..0 # SKIP these tests are for testing by the author\n"; exit } } use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 1.09 use Test::Version; my @imports = qw( version_all_ok ); my $params = { is_strict => 0, has_version => 1, multiple => 0, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; Net-Works-0.22/t/Address.t0000644000175000017500000001664412756362344015172 0ustar autarchautarchuse strict; use warnings; use Math::BigInt; use Math::Int128 qw(uint128); use Test::Fatal; use Test::More 0.88; use Net::Works::Address; { my $ip = Net::Works::Address->new_from_string( string => '1.2.3.4' ); is( $ip->as_string(), '1.2.3.4', '->as_string returns string passed to constructor' ); my $next = $ip->next_ip(); isa_ok( $next, 'Net::Works::Address', 'return value of ->next_ip' ); is( $next->as_string(), '1.2.3.5', 'next ip after 1.2.3.4 is 1.2.3.5' ); my $prev = $ip->previous_ip(); isa_ok( $prev, 'Net::Works::Address', 'return value of ->previous_ip' ); is( $prev->as_string(), '1.2.3.3', 'previous ip before 1.2.3.4 is 1.2.3.3' ); is( "$ip", '1.2.3.4', 'stringification of address object works' ); cmp_ok( $ip, '<', $next, 'numeric overloading (<) on address objects works' ); cmp_ok( $next, '>', $ip, 'numeric overloading (>) on address objects works' ); my $same_ip = Net::Works::Address->new_from_string( string => '1.2.3.4' ); cmp_ok( $ip, '==', $same_ip, 'numeric overloading (==) on address objects works' ); is( $ip <=> $same_ip, 0, 'comparison overloading (==) on address objects works' ); } { my @ips = map { Net::Works::Address->new_from_string( string => $_ ) } qw( ::123.0.0.4 ::1.2.3.4 2003:: ::255.255.255.255 abcd::1000 ::127.0.98.25 ::127.0.98.24 ); my @sorted = qw( ::1.2.3.4 ::123.0.0.4 ::127.0.98.24 ::127.0.98.25 ::255.255.255.255 2003:: abcd::1000 ); is_deeply( [ map { $_->as_string() } sort { $a <=> $b } @ips ], \@sorted, 'address objects sort numerically' ); is_deeply( [ map { $_->as_string() } sort { $a cmp $b } @ips ], \@sorted, 'address objects sort alphabetically' ); } { my $ip = Net::Works::Address->new_from_string( string => '192.168.0.255' ) ->next_ip(); is( $ip->as_string(), '192.168.1.0', '->next_ip wraps to the next ip address' ); } { my $ip = Net::Works::Address->new_from_string( string => 'ffff::a:1234' ); is( $ip->as_string(), 'ffff::a:1234', '->as_string returns string passed to constructor' ); my $prev = $ip->previous_ip(); is( $prev->as_string(), 'ffff::a:1233', 'previous ip before ffff::a:1234 is ffff::a:1233' ); my $next = $ip->next_ip(); is( $next->as_string(), 'ffff::a:1235', 'next ip after ffff::a:1234 is ffff::a:1235' ); } { my $ip = Net::Works::Address->new_from_string( string => 'ffff::0000:000a:1234' ); is( $ip->as_string(), 'ffff::a:1234', '->as_string returns compact form of IPv6' ); } { for my $address ( qw( 255.255.255.255 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff )) { my $ip = Net::Works::Address->new_from_string( string => $address ); like( exception { $ip->next_ip() }, qr/\Q$address is the last address in its range/, 'cannot call ->next_ip on the last address in a range' ); } } { for my $address (qw( 0.0.0.0 ::0 )) { my $ip = Net::Works::Address->new_from_string( string => $address ); like( exception { $ip->previous_ip() }, qr/\Q$address is the first address in its range/, 'cannot call ->previous_ip on the first address in a range' ); } } { my $ip = Net::Works::Address->new_from_integer( integer => 0, version => 4, ); is( $ip->as_string(), '0.0.0.0', 'new_from_integer(0), IPv4' ); is( $ip->as_integer(), 0, 'as_integer returns 0' ); is( $ip->as_bit_string(), '0' x 32, 'as_bit_string returns 0x32' ); $ip = Net::Works::Address->new_from_integer( integer => 2**32 - 1, version => 4, ); is( $ip->as_string(), '255.255.255.255', 'new_from_integer(2**32 - 1), IPv4' ); is( $ip->as_integer(), 2**32 - 1, 'as_integer returns 2**32 - 1' ); is( $ip->as_bit_string(), '1' x 32, 'as_bit_string returns 1x32' ); $ip = Net::Works::Address->new_from_integer( integer => 0, version => 6, ); is( $ip->as_string(), '::0', 'new_from_integer(0), IPv6' ); is( $ip->as_integer(), 0, 'as_integer returns 0, IPv6' ); is( $ip->as_bit_string(), '0' x 128, 'as_bit_string returns 0x128' ); $ip = Net::Works::Address->new_from_integer( integer => 2**32 - 1, version => 6, ); is( $ip->as_string(), '::255.255.255.255', 'new_from_integer(2**32 - 1), IPv6' ); is( $ip->as_bit_string(), ( '0' x 96 ) . ( '1' x 32 ), 'as_bit_string returns 0x96 . 1x32' ); is( $ip->as_integer(), 2**32 - 1, 'as_integer returns 2**32 - 1, IPv6' ); } for my $one ( uint128(1), Math::BigInt->bone() ) { subtest 'using ' . ref($one) . ' integer' => sub { my $max_128 = ( $one * 2 )**128 - $one; my $ip = Net::Works::Address->new_from_integer( integer => $max_128, version => 6, ); is( $ip->as_string(), 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', 'new_from_integer(2**128 - 1), IPv6' ); is( $ip->as_integer(), $max_128, 'as_integer returns 2**128 - 1, IPv6' ); is( $ip->as_bit_string(), '1' x 128, 'as_bit_string returns 1x128' ); $ip = Net::Works::Address->new_from_integer( integer => $one, version => 4, ); is( $ip->as_string(), '0.0.0.1', 'as_string returns 0.0.0.1' ); }; } { my $e = exception { Net::Works::Address->new_from_integer( integer => uint128(2)**33, version => 4 ); }; like( $e, qr/\d+ \Qis not a valid integer for an IP address/, 'new_from_integer blows up when giving a value larger than 2**32 -1 with version => 4' ); } { my %tests = ( '::0' => '0.0.0.0', '::2' => '0.0.0.2', '::ffff' => '0.0.255.255', '::ffff:ffff' => '255.255.255.255', ); for my $raw ( sort keys %tests ) { my $ip = Net::Works::Address->new_from_string( string => $raw, version => 6, ); is( $ip->as_ipv4_string(), $tests{$raw}, "$raw as IPv4 is $tests{$raw}" ); } } { my $ip = Net::Works::Address->new_from_string( string => '::1:ffff:ffff', version => 6, ); like( exception { $ip->as_ipv4_string() }, qr/\QCannot represent IP address larger than 2**32-1 as an IPv4 string/, 'cannot represent an IPv6 address >= 2**32 as an IPv4 string' ); } done_testing(); Net-Works-0.22/t/author-pod-coverage.t0000644000175000017500000000241312756362344017445 0ustar autarchautarch#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print "1..0 # SKIP these tests are for testing by the author\n"; exit } } # This file was automatically generated by Dist::Zilla::Plugin::Test::Pod::Coverage::Configurable. use Test::Pod::Coverage 1.08; use Test::More 0.88; BEGIN { if ( $] <= 5.008008 ) { plan skip_all => 'These tests require Pod::Coverage::TrustPod, which only works with Perl 5.8.9+'; } } use Pod::Coverage::TrustPod; { package My::Coverage; use parent 'Pod::Coverage::Moose', 'Pod::Coverage::TrustPod'; $INC{'My/Coverage.pm'} = 1; } my %skip = map { $_ => 1 } qw( Net::Works::Role::IP Net::Works::Types Net::Works::Types::Internal ); my @modules; for my $module ( all_modules() ) { next if $skip{$module}; push @modules, $module; } plan skip_all => 'All the modules we found were excluded from POD coverage test.' unless @modules; plan tests => scalar @modules; my %trustme = (); my @also_private; for my $module ( sort @modules ) { pod_coverage_ok( $module, { coverage_class => 'My::Coverage', also_private => \@also_private, trustme => $trustme{$module} || [], }, "pod coverage for $module" ); } done_testing(); Net-Works-0.22/t/00-report-prereqs.t0000644000175000017500000001271412756362344017006 0ustar autarchautarch#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.025 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do 't/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; if ( $source && $HAS_CPAN_META && (my $meta = eval { CPAN::Meta->load_file($source) } ) ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } else { $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( @dep_errors ) { diag join("\n", "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n", "The following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=4 sts=4 sw=4 et: Net-Works-0.22/t/Network.t0000644000175000017500000003234212756362344015227 0ustar autarchautarchuse strict; use warnings; use Test::More 0.88; use Math::BigInt (); use Math::Int128 qw(uint128); use Net::Works::Address; use Net::Works::Network; { my $net = Net::Works::Network->new_from_string( string => '1.1.1.0/28' ); is( $net->as_string(), '1.1.1.0/28', 'as_string returns value passed to the constructor' ); is( $net->prefix_length(), 28, 'prefix_length is 28' ); my $first_ip = $net->first(); isa_ok( $first_ip, 'Net::Works::Address', 'return value of ->first' ); is( $first_ip->as_string(), '1.1.1.0', '->first returns the correct IP address' ); my $last_ip = $net->last(); isa_ok( $last_ip, 'Net::Works::Address', 'return value of ->last' ); is( $last_ip->as_string(), '1.1.1.15', '->last returns the correct IP address' ); _test_iterator( $net, 16, [ map { "1.1.1.$_" } 0 .. 15 ], ); is( "$net", '1.1.1.0/28', 'stringification of network object works' ); my $greater = Net::Works::Network->new_from_string( string => '2.0.0.0/24' ); cmp_ok( $net, '<', $greater, 'numeric overloading (<) on network objects works' ); cmp_ok( $greater, '>', $net, 'numeric overloading (>) on network objects works' ); my $same_net = Net::Works::Network->new_from_string( string => '1.1.1.0/28' ); cmp_ok( $net, '==', $same_net, 'numeric overloading (==) on network objects works' ); is( $net <=> $same_net, 0, 'comparison overloading (==) on network objects works' ); my $greater_prefix = Net::Works::Network->new_from_string( string => '1.1.1.0/29' ); cmp_ok( $net, '<', $greater_prefix, 'numeric overloading (<) on network objects works (based on prefix length)' ); cmp_ok( $greater_prefix, '>', $net, 'numeric overloading (>) on network objects works (based on prefix length)' ); } { my @networks = map { Net::Works::Network->new_from_string( string => $_ ) } qw( ::123.0.0.4/128 2003::/96 ::1.2.3.0/124 abcd::1000/116 ::255.255.0.0/112 ::127.0.98.0/124 ::127.0.98.0/120 ); my @sorted = qw( ::1.2.3.0/124 ::123.0.0.4/128 ::127.0.98.0/120 ::127.0.98.0/124 ::255.255.0.0/112 2003::/96 abcd::1000/116 ); is_deeply( [ map { $_->as_string() } sort { $a <=> $b } @networks ], \@sorted, 'network objects sort numerically' ); is_deeply( [ map { $_->as_string() } sort { $a cmp $b } @networks ], \@sorted, 'network objects sort alphabetically' ); } { my $net = Net::Works::Network->new_from_string( string => 'ffff::1200/120' ); is( $net->as_string(), 'ffff::1200/120', 'as_string returns value passed to the constructor' ); is( $net->prefix_length(), 120, 'prefix_length is 120', ); my $first_ip = $net->first(); isa_ok( $first_ip, 'Net::Works::Address', 'return value of ->first' ); is( $first_ip->as_string(), 'ffff::1200', '->first returns the correct IP address' ); my $last_ip = $net->last(); isa_ok( $last_ip, 'Net::Works::Address', 'return value of ->last' ); is( $last_ip->as_string(), 'ffff::12ff', '->last returns the correct IP address' ); _test_iterator( $net, 256, [ map { sprintf( 'ffff::12%02x', $_ ) } 0 .. 255 ], ); } { my $net = Net::Works::Network->new_from_string( string => '1.1.1.1/32' ); _test_iterator( $net, 1, ['1.1.1.1'], ); } { my $net = Net::Works::Network->new_from_string( string => '1.1.1.0/31' ); _test_iterator( $net, 2, [ '1.1.1.0', '1.1.1.1' ], ); } { my $net = Net::Works::Network->new_from_string( string => '1.1.1.4/30' ); _test_iterator( $net, 4, [ '1.1.1.4', '1.1.1.5', '1.1.1.6', '1.1.1.7' ], ); } { my %tests = ( ( map { '100.99.98.0/' . $_ => 23 } 23 .. 32 ), ( map { '100.99.16.0/' . $_ => 20 } 20 .. 32 ), ( map { '1.1.1.0/' . $_ => 24 } 24 .. 32 ), ( map { 'ffff::/' . $_ => 16 } 16 .. 128 ), ( map { 'ffff:ff00::/' . $_ => 24 } 24 .. 128 ), ); for my $subnet ( sort keys %tests ) { my $net = Net::Works::Network->new_from_string( string => $subnet ); is( $net->max_prefix_length(), $tests{$subnet}, "max_prefix_length for $subnet is $tests{$subnet}" ); } } { my %contains = ( '1.1.1.0/24' => { true => [ qw( 1.1.1.0 1.1.1.1 1.1.1.254 1.1.1.254 1.1.1.0/24 1.1.1.0/26 1.1.1.255/32 ) ], false => [ qw( 1.1.2.0 1.1.0.255 240.1.2.3 1.1.0.0/16 1.1.0.0/24 11.12.13.14/32 ) ], }, '97.0.0.0/8' => { true => [ qw( 97.0.0.0 97.1.2.3 97.200.201.203 97.255.255.254 97.255.255.255 97.9.0.0/24 97.55.0.0/16 97.0.0.0/8 97.255.255.255/32 ) ], false => [ qw( 96.255.255.255 98.0.0.0 1.1.1.32 240.1.2.3 96.0.0.0/4 98.0.0.0/8 11.12.13.14/32 ) ], }, '1000::/8' => { true => [ qw( 1000:: 1000::1 10bc:def9:1234::0 10ff:ffff:ffff:ffff:ffff:ffff:ffff:fffe 10ff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 1000::/8 1000::/16 1034::1/128 10ff::/124 10ff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 ) ], false => [ qw( 0fff:: 0fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff f::f 1100:: 1000::/4 2000::/120 ffff::/128 ) ], }, ); for my $n ( sort keys %contains ) { my $network = Net::Works::Network->new_from_string( string => $n ); for my $string ( @{ $contains{$n}{true} } ) { my $object = _objectify_string($string); ok( $network->contains($object), $network->as_string() . ' contains ' . $object->as_string() ); } for my $string ( @{ $contains{$n}{false} } ) { my $object = _objectify_string($string); ok( !$network->contains($object), $network->as_string() . ' does not contain ' . $object->as_string() ); } } } { my @splits = ( [ '1.1.1.0/24' => [ '1.1.1.0/25', '1.1.1.128/25' ] ], [ '1.1.1.128/25' => [ '1.1.1.128/26', '1.1.1.192/26' ] ], [ '1.1.1.192/26' => [ '1.1.1.192/27', '1.1.1.224/27' ] ], [ '1.1.1.224/27' => [ '1.1.1.224/28', '1.1.1.240/28' ] ], [ '1.1.1.240/28' => [ '1.1.1.240/29', '1.1.1.248/29' ] ], [ '1.1.1.248/29' => [ '1.1.1.248/30', '1.1.1.252/30' ] ], [ '1.1.1.252/30' => [ '1.1.1.252/31', '1.1.1.254/31' ] ], [ '1.1.1.254/31' => [ '1.1.1.254/32', '1.1.1.255/32' ] ], [ '9000::/8' => [ '9000::/9', '9080::/9' ] ], [ '9080::/9' => [ '9080::/10', '90c0::/10' ] ], [ '90c0::/10' => [ '90c0::/11', '90e0::/11' ] ], [ '90e0::/11' => [ '90e0::/12', '90f0::/12' ] ], [ '90f0::/12' => [ '90f0::/13', '90f8::/13' ] ], [ '90f8::/13' => [ '90f8::/14', '90fc::/14' ] ], [ '90fc::/14' => [ '90fc::/15', '90fe::/15' ] ], [ '90fe::/15' => [ '90fe::/16', '90ff::/16' ] ], ); for my $pair (@splits) { my $original = Net::Works::Network->new_from_string( string => $pair->[0] ); my @halves = $original->split(); is_deeply( [ map { $_->as_string() } $original->split() ], $pair->[1], "$pair->[0] splits into $pair->[1][0] and $pair->[1][1]" ); } is_deeply( [ Net::Works::Network->new_from_string( string => '1.1.1.1/32' ) ->split() ], [], 'split() returns an empty list for single address IPv4 network' ); is_deeply( [ Net::Works::Network->new_from_string( string => '9999::abcd/128' )->split() ], [], 'split() returns an empty list for single address IPv6 network' ); } { my $net = Net::Works::Network->new_from_string( string => '::/0' ); is( $net->as_string(), '::0/0', 'got subnet passed to constructor' ); is( $net->first()->as_string(), '::0', 'first address in network is ::0' ); } for my $two ( uint128(2), Math::BigInt->new(2) ) { subtest 'using ' . ref($two) . ' integer' => sub { { my $int = $two * 0; my $net = Net::Works::Network->new_from_integer( integer => $int, prefix_length => 32, version => 4, ); is( $net->as_string(), '0.0.0.0/32', 'a network created via new_from_integer with version => 4 stringifies correctly' ); } my $net = Net::Works::Network->new_from_integer( integer => ( $two**32 ), prefix_length => 96, ); is( $net->as_string(), '::1:0:0/96', 'as_string for network created via new_from_integer with 2**32' ); $net = Net::Works::Network->new_from_integer( integer => ( $two**64 ), prefix_length => 96, ); is( $net->as_string(), '0:0:0:1::/96', 'as_string for network created via new_from_integer with 2**64' ); $net = Net::Works::Network->new_from_integer( integer => ( $two**96 ), prefix_length => 96, ); is( $net->as_string(), '0:1::/96', 'as_string for network created via new_from_integer with 2**96' ); }; } { my $net = Net::Works::Network->new_from_string( string => '128.0.0.0/1' ); is( $net->last()->as_string(), '255.255.255.255', 'last address for 128.0.0.0/1 is 255.255.255.255' ); $net = Net::Works::Network->new_from_string( string => '0.0.0.0/0' ); is( $net->last()->as_string(), '255.255.255.255', 'last address for 0.0.0.0/0 is 255.255.255.255' ); } { my $net = Net::Works::Network->new_from_string( string => '8000::/1' ); is( $net->last()->as_string(), ( join ':', ('ffff') x 8 ), q{last address for 8000:/1 is all ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff} ); $net = Net::Works::Network->new_from_string( string => '::0/0' ); is( $net->last()->as_string(), ( join ':', ('ffff') x 8 ), q{last address for ::0/0 is all ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff} ); } { my $from_string = Net::Works::Network->new_from_string( string => '::0/128' ); is( $from_string->as_string(), '::0/128', q{net from string '::0/128' stringifies to '::0/128'} ); my $from_integer = Net::Works::Network->new_from_integer( integer => 0, prefix_length => 128, version => 6, ); is( $from_integer->as_string(), '::0/128', q{net from integer 0 (prefix length 128) stringifies to '::0/128'} ); } { my @single = qw( 0.0.0.0/32 1.2.3.4/32 255.255.255.255/32 ::0/128 ::a/128 1234:5678:9abc:def0:1234:5678:9abc:def0/128 ); for my $s (@single) { ok( Net::Works::Network->new_from_string( string => $s ) ->is_single_address, "$s is a single address network" ); } my @multi = qw( 0.0.0.0/31 1.2.3.4/31 63.255.255.255/2 ::0/127 ::a/1 1234:5678:9abc:def0:1234::/78 ); for my $m (@multi) { ok( !Net::Works::Network->new_from_string( string => $m ) ->is_single_address, "$m is not a single address network" ); } } sub _test_iterator { my $net = shift; my $expect_count = shift; my $expect_addresses = shift; my $iter = $net->iterator(); my @addresses; while ( my $address = $iter->() ) { push @addresses, $address; } is( scalar @addresses, $expect_count, "iterator returned $expect_count addresses" ); is_deeply( [ map { $_->as_string() } @addresses ], $expect_addresses, "iterator returned $expect_addresses->[0] - $expect_addresses->[-1]" ); } sub _objectify_string { my $string = shift; return $string =~ m{/} ? Net::Works::Network->new_from_string( string => $string ) : Net::Works::Address->new_from_string( string => $string ); } done_testing(); Net-Works-0.22/t/release-tidyall.t0000644000175000017500000000061212756362344016651 0ustar autarchautarch BEGIN { unless ($ENV{RELEASE_TESTING}) { print "1..0 # SKIP these tests are for release candidate testing\n"; exit } } # This file was automatically generated by Dist::Zilla::Plugin::Test::TidyAll v$VERSION use Test::More 0.88; use Test::Code::TidyAll 0.24; tidyall_ok( verbose => ( exists $ENV{TEST_TIDYALL_VERBOSE} ? $ENV{TEST_TIDYALL_VERBOSE} : 0 ), ); done_testing(); Net-Works-0.22/t/author-pod-syntax.t0000644000175000017500000000045212756362344017201 0ustar autarchautarch#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print "1..0 # SKIP these tests are for testing by the author\n"; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Net-Works-0.22/t/author-synopsis.t0000644000175000017500000000026012756362344016757 0ustar autarchautarch#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print "1..0 # SKIP these tests are for testing by the author\n"; exit } } use Test::Synopsis; all_synopsis_ok(); Net-Works-0.22/t/author-00-compile.t0000644000175000017500000000264412756362344016745 0ustar autarchautarch BEGIN { unless ($ENV{AUTHOR_TESTING}) { print "1..0 # SKIP these tests are for testing by the author\n"; exit } } use 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.054 use Test::More; plan tests => 7; my @module_files = ( 'Net/Works.pm', 'Net/Works/Address.pm', 'Net/Works/Network.pm', 'Net/Works/Role/IP.pm', 'Net/Works/Types.pm', 'Net/Works/Util.pm' ); # no fake home requested my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ and not eval { require blib; blib->VERSION('1.01') }; if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ); Net-Works-0.22/t/release-cpan-changes.t0000644000175000017500000000055112756362344017540 0ustar autarchautarch BEGIN { unless ($ENV{RELEASE_TESTING}) { print "1..0 # SKIP these tests are for release candidate testing\n"; exit } } use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::CPAN::Changes 0.012 use Test::More 0.96 tests => 1; use Test::CPAN::Changes; subtest 'changes_ok' => sub { changes_file_ok('Changes'); }; Net-Works-0.22/t/author-eol.t0000644000175000017500000000173612756362344015660 0ustar autarchautarch BEGIN { unless ($ENV{AUTHOR_TESTING}) { print "1..0 # SKIP these tests are for testing by the author\n"; exit } } use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::EOL 0.19 use Test::More 0.88; use Test::EOL; my @files = ( 'lib/Net/Works.pm', 'lib/Net/Works/Address.pm', 'lib/Net/Works/Network.pm', 'lib/Net/Works/Role/IP.pm', 'lib/Net/Works/Types.pm', 'lib/Net/Works/Util.pm', 't/00-report-prereqs.dd', 't/00-report-prereqs.t', 't/Address.t', 't/Network-splitting.t', 't/Network.t', 't/author-00-compile.t', 't/author-eol.t', 't/author-no-tabs.t', 't/author-pod-coverage.t', 't/author-pod-spell.t', 't/author-pod-syntax.t', 't/author-portability.t', 't/author-synopsis.t', 't/author-test-version.t', 't/bad-data.t', 't/release-cpan-changes.t', 't/release-tidyall.t' ); eol_unix_ok($_, { trailing_whitespace => 1 }) foreach @files; done_testing; Net-Works-0.22/t/author-no-tabs.t0000644000175000017500000000170412756362344016437 0ustar autarchautarch BEGIN { unless ($ENV{AUTHOR_TESTING}) { print "1..0 # SKIP these tests are for testing by the author\n"; exit } } use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::NoTabs 0.15 use Test::More 0.88; use Test::NoTabs; my @files = ( 'lib/Net/Works.pm', 'lib/Net/Works/Address.pm', 'lib/Net/Works/Network.pm', 'lib/Net/Works/Role/IP.pm', 'lib/Net/Works/Types.pm', 'lib/Net/Works/Util.pm', 't/00-report-prereqs.dd', 't/00-report-prereqs.t', 't/Address.t', 't/Network-splitting.t', 't/Network.t', 't/author-00-compile.t', 't/author-eol.t', 't/author-no-tabs.t', 't/author-pod-coverage.t', 't/author-pod-spell.t', 't/author-pod-syntax.t', 't/author-portability.t', 't/author-synopsis.t', 't/author-test-version.t', 't/bad-data.t', 't/release-cpan-changes.t', 't/release-tidyall.t' ); notabs_ok($_) foreach @files; done_testing; Net-Works-0.22/t/bad-data.t0000644000175000017500000001431612756362344015234 0ustar autarchautarchuse strict; use warnings; use B; use Math::Int128 qw( uint128 ); use Test::Fatal; use Test::More 0.88; use Net::Works::Address; use Net::Works::Network; { for my $bad_num ( undef, qw( -1 1.1 a-string google.com ), 2**33 ) { my $str_val = defined $bad_num ? $bad_num : 'undef'; like( exception { Net::Works::Address->new_from_integer( integer => $bad_num, version => 4, ); }, qr/\Q$str_val is not a valid integer for an IP address/, "Net::Works::Address->new_from_integer() died with $str_val as integer (v4)" ); like( exception { Net::Works::Network->new_from_integer( integer => $bad_num, prefix_length => 20, version => 4, ); }, qr/\Q$str_val is not a valid integer for an IP address/, "Net::Works::Network->new_from_integer() died with $str_val as integer (v4)" ); } } { for my $bad_num ( undef, qw( -1 1.1 a-string google.com ) ) { my $str_val = defined $bad_num ? $bad_num : 'undef'; like( exception { Net::Works::Address->new_from_integer( integer => $bad_num, version => 6, ); }, qr/\Q$str_val is not a valid integer for an IP address/, "Net::Works::Address->new_from_integer() died with $str_val as integer (v6)" ); like( exception { Net::Works::Network->new_from_integer( integer => $bad_num, prefix_length => 20, version => 6, ); }, qr/\Q$str_val is not a valid integer for an IP address/, "Net::Works::Network->new_from_integer() died with $str_val as integer (v6)" ); } } { for my $bad_str ( undef, qw( -1 1.1 a-string google.com 1.2.3.555 a.3.4.5 ), ) { my $str_val = defined $bad_str ? $bad_str : 'undef'; like( exception { Net::Works::Address->new_from_string( string => $bad_str, version => 4, ); }, qr/\Q$str_val is not a valid IPv4 address/, "Net::Works::Address->new_from_string() died with $str_val as string (v4)" ); $str_val = "$bad_str/20" if defined $bad_str; like( exception { Net::Works::Network->new_from_string( string => ( defined $bad_str ? "$bad_str/20" : $bad_str ), version => 4, ); }, qr/\Q$str_val is not a valid IP network/, "Net::Works::Network->new_from_string() died with $str_val as string (v4)" ); } } { for my $bad_str ( undef, qw( -1 1.1 a-string google.com 1.2.3.555 a.3.4.5 fffff:: abcd::1234::4321 g123::1234 ), ) { my $str_val = defined $bad_str ? $bad_str : 'undef'; like( exception { Net::Works::Address->new_from_string( string => $bad_str, version => 6, ); }, qr/\Q$str_val is not a valid IPv6 address/, "Net::Works::Address->new_from_string() died with $str_val as string (v4)" ); $str_val = "$bad_str/20" if defined $bad_str; like( exception { Net::Works::Network->new_from_string( string => ( defined $bad_str ? "$bad_str/20" : $bad_str ), version => 6, ); }, qr/\Q$str_val is not a valid IP network/, "Net::Works::Network->new_from_string() died with $str_val as string (v4)" ); } } { for my $bad ( '1.1.1.1/-1', '1.1.1.1/33', '1.1.1.0/24;', "1.1.1.0/24\n", '1.1.1.1/', '1.1.1.1', '11.0.0.0/10/10', ) { ## no critic (Subroutines::ProhibitCallsToUnexportedSubs) my $safe_bad = B::perlstring($bad); like( exception { Net::Works::Network->new_from_string( string => $bad, version => 4, ); }, qr/\Qis not a valid IP network prefix length/, "Net::Works::Address->new_from_string( string => $safe_bad, version => 4 ) died with bad prefix" ); } for my $bad ( undef, 'whatever', '1.1.1' ) { ## no critic (Subroutines::ProhibitCallsToUnexportedSubs) my $safe_bad = B::perlstring($bad); like( exception { Net::Works::Network->new_from_string( string => $bad, version => 4, ); }, qr/\Qis not a valid IP network/, "Net::Works::Address->new_from_string( string => $safe_bad, version => 4 ) died with bad prefix" ); } for my $bad ( '::1/-1', '::1/129', '::1/120;', "::1/120\n", '::1.1.1.1', '::1000', ) { ## no critic (Subroutines::ProhibitCallsToUnexportedSubs) my $safe_bad = B::perlstring($bad); like( exception { Net::Works::Network->new_from_string( string => $bad, version => 6, ); }, qr/\Qis not a valid IP network prefix length/, "Net::Works::Address->new_from_string( string => $safe_bad, version => 6 ) died with bad prefix" ); } for my $bad ( undef, 'whatever' ) { ## no critic (Subroutines::ProhibitCallsToUnexportedSubs) my $safe_bad = B::perlstring($bad); like( exception { Net::Works::Network->new_from_string( string => $bad, version => 6, ); }, qr/\Qis not a valid IP network/, "Net::Works::Address->new_from_string( string => $safe_bad, version => 6 ) died with bad prefix" ); } } done_testing(); Net-Works-0.22/t/00-report-prereqs.dd0000644000175000017500000000622412756362344017131 0ustar autarchautarchdo { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '0', 'perl' => '5.010000' } }, 'develop' => { 'requires' => { 'File::Spec' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', 'Perl::Critic' => '1.123', 'Perl::Tidy' => '20140711', 'Pod::Coverage::Moose' => '0', 'Pod::Coverage::TrustPod' => '0', 'Test::CPAN::Changes' => '0.19', 'Test::Code::TidyAll' => '0.24', 'Test::EOL' => '0', 'Test::More' => '0.88', 'Test::NoTabs' => '0', 'Test::Pod' => '1.41', 'Test::Pod::Coverage' => '1.08', 'Test::Portability::Files' => '0', 'Test::Spelling' => '0.12', 'Test::Synopsis' => '0', 'Test::Version' => '1' } }, 'runtime' => { 'requires' => { 'Carp' => '0', 'Exporter' => '0', 'List::AllUtils' => '0', 'Math::Int128' => '0.06', 'Moo' => '0', 'Moo::Role' => '0', 'Scalar::Util' => '0', 'Socket' => '1.99', 'Sub::Quote' => '0', 'integer' => '0', 'namespace::autoclean' => '0.16', 'overload' => '0', 'perl' => '5.010', 'strict' => '0', 'warnings' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'B' => '0', 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'Math::BigInt' => '0', 'Test::Fatal' => '0', 'Test::More' => '0.96', 'perl' => '5.010' } } }; $x; }Net-Works-0.22/t/author-portability.t0000644000175000017500000000046712756362344017443 0ustar autarchautarch BEGIN { unless ($ENV{AUTHOR_TESTING}) { print "1..0 # SKIP these tests are for testing by the author\n"; exit } } use strict; use warnings; use Test::More; eval 'use Test::Portability::Files'; plan skip_all => 'Test::Portability::Files required for testing portability' if $@; run_tests(); Net-Works-0.22/t/author-pod-spell.t0000644000175000017500000000125412756362344016773 0ustar autarchautarch BEGIN { unless ($ENV{AUTHOR_TESTING}) { print "1..0 # SKIP these tests are for testing by the author\n"; exit } } use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.007002 use Test::Spelling 0.12; use Pod::Wordlist; add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ Alders Alders' Eilam Eilam's MaxMind MaxMind's Oschwald Oschwald's Rolsky Rolsky's API APIs Hartmaier IANA IP IPv TJ distro distro's netmask subnet subnets Dave autarch Greg oschwald Olaf oalders Inc Alexander abraxxa drolsky goschwald Mather tjmather William Stevenson wstevenson lib Net Works Address Network Role Types Util Net-Works-0.22/t/Network-splitting.t0000644000175000017500000003710112756362344017240 0ustar autarchautarchuse strict; use warnings; use Test::More 0.88; use List::AllUtils qw( each_array ); use Math::Int128 qw(uint128); use Net::Works::Address; use Net::Works::Network; { _test_remove_reserved_subnets( [ '0.0.0.1', '1.2.3.4' ] => [ [ '1.0.0.0', '1.2.3.4' ] ] ); _test_remove_reserved_subnets( [ '9.10.11.12', '9.255.255.255' ] => [ [ '9.10.11.12', '9.255.255.255' ] ] ); _test_remove_reserved_subnets( [ '9.0.0.0', '12.0.0.0' ] => [ [ '9.0.0.0', '9.255.255.255' ], [ '11.0.0.0', '12.0.0.0' ], ] ); _test_remove_reserved_subnets( [ '9.0.0.0', '10.255.255.255' ] => [ [ '9.0.0.0', '9.255.255.255' ], ] ); _test_remove_reserved_subnets( [ '10.2.3.4', '12.255.255.255' ] => [ [ '11.0.0.0', '12.255.255.255' ], ] ); _test_remove_reserved_subnets( [ '10.0.0.0', '10.10.10.10' ] => [] ); _test_remove_reserved_subnets( [ '0.0.0.0', '255.255.255.255' ] => [ [ '1.0.0.0', '9.255.255.255' ], [ '11.0.0.0', '100.63.255.255' ], [ '100.128.0.0', '126.255.255.255' ], [ '128.0.0.0', '169.253.255.255' ], [ '169.255.0.0', '172.15.255.255' ], [ '172.32.0.0', '191.255.255.255' ], [ '192.0.0.8', '192.0.1.255' ], [ '192.0.3.0', '192.88.98.255' ], [ '192.88.100.0', '192.167.255.255' ], [ '192.169.0.0', '198.17.255.255' ], [ '198.20.0.0', '198.51.99.255' ], [ '198.51.101.0', '203.0.112.255' ], [ '203.0.114.0', '223.255.255.255' ], ] ); _test_remove_reserved_subnets( [ '::0', 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' ] => [ map { [ map { Net::Works::Address->new_from_string( string => $_, version => 6 )->as_string() } @{$_} ] } ( [ '::1.0.0.0', '::9.255.255.255' ], [ '::11.0.0.0', '::100.63.255.255' ], [ '::100.128.0.0', '::126.255.255.255' ], [ '::128.0.0.0', '::169.253.255.255' ], [ '::169.255.0.0', '::172.15.255.255' ], [ '::172.32.0.0', '::191.255.255.255' ], [ '::192.0.0.8', '::192.0.1.255' ], [ '::192.0.3.0', '::192.88.98.255' ], [ '::192.88.100.0', '::192.167.255.255' ], [ '::192.169.0.0', '::198.17.255.255' ], [ '::198.20.0.0', '::198.51.99.255' ], [ '::198.51.101.0', '::203.0.112.255' ], [ '::203.0.114.0', '::223.255.255.255' ], [ '::1:0:0', 'ff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', ], [ '100:0000:0000:0001::', '2000:ffff:ffff:ffff:ffff:ffff:ffff:ffff', ], [ '2001:0200::', '2001:db7:ffff:ffff:ffff:ffff:ffff:ffff', ], [ '2001:db9::', 'fbff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', ], [ 'fe00::', 'fe7f:ffff:ffff:ffff:ffff:ffff:ffff:ffff', ], [ 'fec0::', 'feff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', ], ), ], ); } { my $start = '1.0.0.1'; my $end = '1.0.0.255'; my @expect = ( map { Net::Works::Network->new_from_string( string => $_ ) } qw( 1.0.0.1/32 1.0.0.2/31 1.0.0.4/30 1.0.0.8/29 1.0.0.16/28 1.0.0.32/27 1.0.0.64/26 1.0.0.128/25 ) ); _test_range_as_subnets( $start, $end, \@expect ); } { my $start = '10.0.0.0'; my $end = '12.0.0.0'; my @expect = ( map { Net::Works::Network->new_from_string( string => $_ ) } qw( 11.0.0.0/8 12.0.0.0/32 ) ); _test_range_as_subnets( $start, $end, \@expect ); } { my $start = '10.0.0.0'; my $end = '12.0.0.0'; my @expect = ( map { Net::Works::Network->new_from_string( string => $_ ) } qw( ::11.0.0.0/104 ::12.0.0.0/128 ) ); _test_range_as_subnets( $start, $end, \@expect, 6 ); } { my $start = '0.0.0.1'; my $end = '19.255.255.255'; my @expect = ( map { Net::Works::Network->new_from_string( string => $_ ) } qw( 1.0.0.0/8 2.0.0.0/7 4.0.0.0/6 8.0.0.0/7 11.0.0.0/8 12.0.0.0/6 16.0.0.0/6 ) ); _test_range_as_subnets( $start, $end, \@expect ); } { my $start = '::1'; my $end = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'; my @expect = ( map { Net::Works::Network->new_from_string( string => $_, version => 6 ) } qw( ::1.0.0.0/104 ::2.0.0.0/103 ::4.0.0.0/102 ::8.0.0.0/103 ::11.0.0.0/104 ::12.0.0.0/102 ::16.0.0.0/100 ::32.0.0.0/99 ::64.0.0.0/99 ::96.0.0.0/102 ::100.0.0.0/106 ::100.128.0.0/105 ::101.0.0.0/104 ::102.0.0.0/103 ::104.0.0.0/101 ::112.0.0.0/101 ::120.0.0.0/102 ::124.0.0.0/103 ::126.0.0.0/104 ::128.0.0.0/99 ::160.0.0.0/101 ::168.0.0.0/104 ::169.0.0.0/105 ::169.128.0.0/106 ::169.192.0.0/107 ::169.224.0.0/108 ::169.240.0.0/109 ::169.248.0.0/110 ::169.252.0.0/111 ::169.255.0.0/112 ::170.0.0.0/103 ::172.0.0.0/108 ::172.32.0.0/107 ::172.64.0.0/106 ::172.128.0.0/105 ::173.0.0.0/104 ::174.0.0.0/103 ::176.0.0.0/100 ::192.0.0.8/125 ::192.0.0.16/124 ::192.0.0.32/123 ::192.0.0.64/122 ::192.0.0.128/121 ::192.0.1.0/120 ::192.0.3.0/120 ::192.0.4.0/118 ::192.0.8.0/117 ::192.0.16.0/116 ::192.0.32.0/115 ::192.0.64.0/114 ::192.0.128.0/113 ::192.1.0.0/112 ::192.2.0.0/111 ::192.4.0.0/110 ::192.8.0.0/109 ::192.16.0.0/108 ::192.32.0.0/107 ::192.64.0.0/108 ::192.80.0.0/109 ::192.88.0.0/114 ::192.88.64.0/115 ::192.88.96.0/119 ::192.88.98.0/120 ::192.88.100.0/118 ::192.88.104.0/117 ::192.88.112.0/116 ::192.88.128.0/113 ::192.89.0.0/112 ::192.90.0.0/111 ::192.92.0.0/110 ::192.96.0.0/107 ::192.128.0.0/107 ::192.160.0.0/109 ::192.169.0.0/112 ::192.170.0.0/111 ::192.172.0.0/110 ::192.176.0.0/108 ::192.192.0.0/106 ::193.0.0.0/104 ::194.0.0.0/103 ::196.0.0.0/103 ::198.0.0.0/108 ::198.16.0.0/111 ::198.20.0.0/110 ::198.24.0.0/109 ::198.32.0.0/108 ::198.48.0.0/111 ::198.50.0.0/112 ::198.51.0.0/114 ::198.51.64.0/115 ::198.51.96.0/118 ::198.51.101.0/120 ::198.51.102.0/119 ::198.51.104.0/117 ::198.51.112.0/116 ::198.51.128.0/113 ::198.52.0.0/110 ::198.56.0.0/109 ::198.64.0.0/106 ::198.128.0.0/105 ::199.0.0.0/104 ::200.0.0.0/103 ::202.0.0.0/104 ::203.0.0.0/114 ::203.0.64.0/115 ::203.0.96.0/116 ::203.0.112.0/120 ::203.0.114.0/119 ::203.0.116.0/118 ::203.0.120.0/117 ::203.0.128.0/113 ::203.1.0.0/112 ::203.2.0.0/111 ::203.4.0.0/110 ::203.8.0.0/109 ::203.16.0.0/108 ::203.32.0.0/107 ::203.64.0.0/106 ::203.128.0.0/105 ::204.0.0.0/102 ::208.0.0.0/100 ::1:0:0/96 ::2:0:0/95 ::4:0:0/94 ::8:0:0/93 ::10:0:0/92 ::20:0:0/91 ::40:0:0/90 ::80:0:0/89 ::100:0:0/88 ::200:0:0/87 ::400:0:0/86 ::800:0:0/85 ::1000:0:0/84 ::2000:0:0/83 ::4000:0:0/82 ::8000:0:0/81 ::1:0:0:0/80 ::2:0:0:0/79 ::4:0:0:0/78 ::8:0:0:0/77 ::10:0:0:0/76 ::20:0:0:0/75 ::40:0:0:0/74 ::80:0:0:0/73 ::100:0:0:0/72 ::200:0:0:0/71 ::400:0:0:0/70 ::800:0:0:0/69 ::1000:0:0:0/68 ::2000:0:0:0/67 ::4000:0:0:0/66 ::8000:0:0:0/65 0:0:0:1::/64 0:0:0:2::/63 0:0:0:4::/62 0:0:0:8::/61 0:0:0:10::/60 0:0:0:20::/59 0:0:0:40::/58 0:0:0:80::/57 0:0:0:100::/56 0:0:0:200::/55 0:0:0:400::/54 0:0:0:800::/53 0:0:0:1000::/52 0:0:0:2000::/51 0:0:0:4000::/50 0:0:0:8000::/49 0:0:1::/48 0:0:2::/47 0:0:4::/46 0:0:8::/45 0:0:10::/44 0:0:20::/43 0:0:40::/42 0:0:80::/41 0:0:100::/40 0:0:200::/39 0:0:400::/38 0:0:800::/37 0:0:1000::/36 0:0:2000::/35 0:0:4000::/34 0:0:8000::/33 0:1::/32 0:2::/31 0:4::/30 0:8::/29 0:10::/28 0:20::/27 0:40::/26 0:80::/25 0:100::/24 0:200::/23 0:400::/22 0:800::/21 0:1000::/20 0:2000::/19 0:4000::/18 0:8000::/17 1::/16 2::/15 4::/14 8::/13 10::/12 20::/11 40::/10 80::/9 100:0:0:1::/64 100:0:0:2::/63 100:0:0:4::/62 100:0:0:8::/61 100:0:0:10::/60 100:0:0:20::/59 100:0:0:40::/58 100:0:0:80::/57 100:0:0:100::/56 100:0:0:200::/55 100:0:0:400::/54 100:0:0:800::/53 100:0:0:1000::/52 100:0:0:2000::/51 100:0:0:4000::/50 100:0:0:8000::/49 100:0:1::/48 100:0:2::/47 100:0:4::/46 100:0:8::/45 100:0:10::/44 100:0:20::/43 100:0:40::/42 100:0:80::/41 100:0:100::/40 100:0:200::/39 100:0:400::/38 100:0:800::/37 100:0:1000::/36 100:0:2000::/35 100:0:4000::/34 100:0:8000::/33 100:1::/32 100:2::/31 100:4::/30 100:8::/29 100:10::/28 100:20::/27 100:40::/26 100:80::/25 100:100::/24 100:200::/23 100:400::/22 100:800::/21 100:1000::/20 100:2000::/19 100:4000::/18 100:8000::/17 101::/16 102::/15 104::/14 108::/13 110::/12 120::/11 140::/10 180::/9 200::/7 400::/6 800::/5 1000::/4 2000::/16 2001:200::/23 2001:400::/22 2001:800::/22 2001:c00::/24 2001:d00::/25 2001:d80::/27 2001:da0::/28 2001:db0::/29 2001:db9::/32 2001:dba::/31 2001:dbc::/30 2001:dc0::/26 2001:e00::/23 2001:1000::/20 2001:2000::/19 2001:4000::/18 2001:8000::/17 2002::/15 2004::/14 2008::/13 2010::/12 2020::/11 2040::/10 2080::/9 2100::/8 2200::/7 2400::/6 2800::/5 3000::/4 4000::/2 8000::/2 c000::/3 e000::/4 f000::/5 f800::/6 fe00::/9 fec0::/10 ) ); _test_range_as_subnets( $start, $end, \@expect ); } done_testing(); sub _test_remove_reserved_subnets { my $range = shift; my $expect = shift; my $version = $range->[0] =~ /:/ ? 6 : 4; # All these conversions are gross but normally this is handled by the # range_as_subnets method. my $first_ip = Net::Works::Address->new_from_string( string => $range->[0], version => $version, )->as_integer(); my $last_ip = Net::Works::Address->new_from_string( string => $range->[1], version => $version )->as_integer(); ## no critic (Subroutines::ProtectPrivateSubs) my @got = map { [ map { Net::Works::Address->new_from_integer( integer => $_, version => $version ) } @{$_} ] } Net::Works::Network->_remove_reserved_subnets_from_range( $first_ip, $last_ip, $version, ); is_deeply( \@got, $expect, "_remove_reserved_subnets_from_range returned expected result for $range->[0] - $range->[1]" ); } sub _test_range_as_subnets { my $start = shift; my $end = shift; my $expect_subnets = shift; my $version = shift; my @subnets = Net::Works::Network->range_as_subnets( $start, $end, $version ); is( scalar @subnets, scalar @{$expect_subnets}, 'got the same number of subnets as we expect' ); my $iter = each_array( @subnets, @{$expect_subnets} ); while ( my ( $got, $expect ) = $iter->() ) { last unless $got && $expect; my $first_ip = eval { $expect->first()->as_ipv4_string() } // $expect->first()->as_string(); is( $got->first()->as_string(), $expect->first()->as_string(), "subnet first matches expected first - split $start - $end ($first_ip)" ); my $last_ip = eval { $expect->last()->as_ipv4_string() } // $expect->last()->as_string(); is( $got->last()->as_string(), $expect->last()->as_string(), "subnet last matches expected last - split $start - $end ($last_ip)" ); my $prefix_length = $expect->prefix_length(); is( $got->prefix_length(), $prefix_length, "prefix length matches expected value - split $start - $end ($prefix_length)" ); } } Net-Works-0.22/Makefile.PL0000644000175000017500000000360212756362344015115 0ustar autarchautarch# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.007. use strict; use warnings; use 5.010; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Sane APIs for IP addresses and networks", "AUTHOR" => "Dave Rolsky , Greg Oschwald , Olaf Alders ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Net-Works", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.010", "NAME" => "Net::Works", "PREREQ_PM" => { "Carp" => 0, "Exporter" => 0, "List::AllUtils" => 0, "Math::Int128" => "0.06", "Moo" => 0, "Moo::Role" => 0, "Scalar::Util" => 0, "Socket" => "1.99", "Sub::Quote" => 0, "integer" => 0, "namespace::autoclean" => "0.16", "overload" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "B" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "Math::BigInt" => 0, "Test::Fatal" => 0, "Test::More" => "0.96" }, "VERSION" => "0.22", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "B" => 0, "Carp" => 0, "Exporter" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "List::AllUtils" => 0, "Math::BigInt" => 0, "Math::Int128" => "0.06", "Moo" => 0, "Moo::Role" => 0, "Scalar::Util" => 0, "Socket" => "1.99", "Sub::Quote" => 0, "Test::Fatal" => 0, "Test::More" => "0.96", "integer" => 0, "namespace::autoclean" => "0.16", "overload" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Net-Works-0.22/META.yml0000644000175000017500000004370412756362344014423 0ustar autarchautarch--- abstract: 'Sane APIs for IP addresses and networks' author: - 'Dave Rolsky ' - 'Greg Oschwald ' - 'Olaf Alders ' build_requires: B: '0' ExtUtils::MakeMaker: '0' File::Spec: '0' Math::BigInt: '0' Test::Fatal: '0' Test::More: '0.96' perl: '5.010' configure_requires: ExtUtils::MakeMaker: '0' perl: '5.010000' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.007, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Net-Works provides: Net::Works: file: lib/Net/Works.pm version: '0.22' Net::Works::Address: file: lib/Net/Works/Address.pm version: '0.22' Net::Works::Network: file: lib/Net/Works/Network.pm version: '0.22' Net::Works::Role::IP: file: lib/Net/Works/Role/IP.pm version: '0.22' Net::Works::Types: file: lib/Net/Works/Types.pm version: '0.22' Net::Works::Util: file: lib/Net/Works/Util.pm version: '0.22' requires: Carp: '0' Exporter: '0' List::AllUtils: '0' Math::Int128: '0.06' Moo: '0' Moo::Role: '0' Scalar::Util: '0' Socket: '1.99' Sub::Quote: '0' integer: '0' namespace::autoclean: '0.16' overload: '0' perl: '5.010' strict: '0' warnings: '0' resources: bugtracker: https://github.com/maxmind/Net-Works/issues repository: git://github.com/maxmind/Net-Works.git version: '0.22' x_Dist_Zilla: perl: version: '5.020002' plugins: - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@MAXMIND/MakeMaker' version: '6.007' - class: Dist::Zilla::Plugin::Authority name: '@MAXMIND/Authority' version: '1.009' - class: Dist::Zilla::Plugin::AutoPrereqs name: '@MAXMIND/AutoPrereqs' version: '6.007' - class: Dist::Zilla::Plugin::CopyFilesFromBuild name: '@MAXMIND/CopyFilesFromBuild' version: '0.161350' - class: Dist::Zilla::Plugin::Git::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: - LICENSE - Makefile.PL - README.md - cpanfile exclude_match: [] follow_symlinks: 0 include_dotfiles: 0 prefix: '' prune_directory: [] root: . Dist::Zilla::Plugin::Git::GatherDir: include_untracked: 0 name: '@MAXMIND/Git::GatherDir' version: '2.039' - class: Dist::Zilla::Plugin::GitHub::Meta name: '@MAXMIND/GitHub::Meta' version: '0.42' - class: Dist::Zilla::Plugin::GitHub::Update config: Dist::Zilla::Plugin::GitHub::Update: metacpan: 1 name: '@MAXMIND/GitHub::Update' version: '0.42' - class: Dist::Zilla::Plugin::MetaProvides::Package config: Dist::Zilla::Plugin::MetaProvides::Package: finder_objects: - class: Dist::Zilla::Plugin::FinderCode name: '@MAXMIND/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: '6.007' include_underscores: 0 Dist::Zilla::Role::MetaProvider::Provider: Dist::Zilla::Role::MetaProvider::Provider::VERSION: '2.001011' inherit_missing: '1' inherit_version: '1' meta_noindex: '1' Dist::Zilla::Role::ModuleMetadata: Module::Metadata: '1.000027' version: '0.004' name: '@MAXMIND/MetaProvides::Package' version: '2.004002' - class: Dist::Zilla::Plugin::NextRelease name: '@MAXMIND/NextRelease' version: '6.007' - class: Dist::Zilla::Plugin::Test::Pod::Coverage::Configurable name: '@MAXMIND/Test::Pod::Coverage::Configurable' version: '0.06' - class: Dist::Zilla::Plugin::Test::PodSpelling config: Dist::Zilla::Plugin::Test::PodSpelling: directories: [] spell_cmd: '' stopwords: - API - APIs - Alders - "Alders'" - Eilam - "Eilam's" - Hartmaier - IANA - IP - IPv - MaxMind - MaxMind - "MaxMind's" - Oschwald - Oschwald - "Oschwald's" - Rolsky - Rolsky - "Rolsky's" - TJ - distro - "distro's" - netmask - subnet - subnets wordlist: Pod::Wordlist name: '@MAXMIND/Test::PodSpelling' version: '2.007002' - class: Dist::Zilla::Plugin::Test::ReportPrereqs name: '@MAXMIND/Test::ReportPrereqs' version: '0.025' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: '@MAXMIND/Test::More with subtest()' version: '6.007' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: develop type: requires name: '@MAXMIND/Modules for use with tidyall' version: '6.007' - class: Dist::Zilla::Plugin::PromptIfStale config: Dist::Zilla::Plugin::PromptIfStale: check_all_plugins: 1 check_all_prereqs: 1 modules: [] phase: release run_under_travis: 0 skip: - Dist::Zilla::Plugin::MAXMIND::Contributors - Dist::Zilla::Plugin::MAXMIND::License - Dist::Zilla::Plugin::MAXMIND::Tidyall name: '@MAXMIND/stale modules, release' version: '0.051' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: '@MAXMIND/ReadmeMarkdownInBuild' version: '0.161170' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: '@MAXMIND/ReadmeMarkdownInRoot' version: '0.161170' - class: Dist::Zilla::Plugin::UploadToCPAN name: '@MAXMIND/UploadToCPAN' version: '6.007' - class: Dist::Zilla::Plugin::SurgicalPodWeaver config: Dist::Zilla::Plugin::PodWeaver: finder: - ':InstallModules' - ':ExecFiles' plugins: - class: Pod::Weaver::Plugin::EnsurePod5 name: '@CorePrep/EnsurePod5' version: '4.013' - class: Pod::Weaver::Plugin::H1Nester name: '@CorePrep/H1Nester' version: '4.013' - class: Pod::Weaver::Section::Name name: Name version: '4.013' - class: Pod::Weaver::Section::Version name: Version version: '4.013' - class: Pod::Weaver::Section::Region name: prelude version: '4.013' - class: Pod::Weaver::Section::Generic name: SYNOPSIS version: '4.013' - class: Pod::Weaver::Section::Generic name: DESCRIPTION version: '4.013' - class: Pod::Weaver::Section::Leftovers name: Leftovers version: '4.013' - class: Pod::Weaver::Section::Region name: postlude version: '4.013' - class: Pod::Weaver::Section::Authors name: Authors version: '4.013' - class: Pod::Weaver::Section::Contributors name: Contributors version: '0.009' - class: Pod::Weaver::Section::Legal name: Legal version: '4.013' name: '@MAXMIND/SurgicalPodWeaver' version: '0.0023' - class: Dist::Zilla::Plugin::PruneCruft name: '@MAXMIND/PruneCruft' version: '6.007' - class: Dist::Zilla::Plugin::ManifestSkip name: '@MAXMIND/ManifestSkip' version: '6.007' - class: Dist::Zilla::Plugin::MetaYAML name: '@MAXMIND/MetaYAML' version: '6.007' - class: Dist::Zilla::Plugin::License name: '@MAXMIND/License' version: '6.007' - class: Dist::Zilla::Plugin::ExtraTests name: '@MAXMIND/ExtraTests' version: '6.007' - class: Dist::Zilla::Plugin::ExecDir name: '@MAXMIND/ExecDir' version: '6.007' - class: Dist::Zilla::Plugin::ShareDir name: '@MAXMIND/ShareDir' version: '6.007' - class: Dist::Zilla::Plugin::Manifest name: '@MAXMIND/Manifest' version: '6.007' - class: Dist::Zilla::Plugin::CheckVersionIncrement name: '@MAXMIND/CheckVersionIncrement' version: '0.121750' - class: Dist::Zilla::Plugin::TestRelease name: '@MAXMIND/TestRelease' version: '6.007' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@MAXMIND/ConfirmRelease' version: '6.007' - class: Dist::Zilla::Plugin::CheckPrereqsIndexed name: '@MAXMIND/CheckPrereqsIndexed' version: '0.018' - class: Dist::Zilla::Plugin::CPANFile name: '@MAXMIND/CPANFile' version: '6.007' - class: Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch config: Dist::Zilla::Role::Git::Repo: repo_root: . name: '@MAXMIND/Git::CheckFor::CorrectBranch' version: '0.013' - class: Dist::Zilla::Plugin::Git::CheckFor::MergeConflicts config: Dist::Zilla::Role::Git::Repo: repo_root: . name: '@MAXMIND/Git::CheckFor::MergeConflicts' version: '0.013' - class: Dist::Zilla::Plugin::Git::Contributors config: Dist::Zilla::Plugin::Git::Contributors: 'git --version': 2.9.3 include_authors: 0 include_releaser: 1 order_by: name paths: - . name: '@MAXMIND/Git::Contributors' version: '0.024' - class: Dist::Zilla::Plugin::InstallGuide name: '@MAXMIND/InstallGuide' version: '1.200007' - class: Dist::Zilla::Plugin::MAXMIND::Contributors name: '@MAXMIND/MAXMIND::Contributors' version: '0.13' - class: Dist::Zilla::Plugin::MAXMIND::License name: '@MAXMIND/MAXMIND::License' version: '0.13' - class: Dist::Zilla::Plugin::MAXMIND::TidyAll name: '@MAXMIND/MAXMIND::TidyAll' version: '0.13' - class: Dist::Zilla::Plugin::Meta::Contributors name: '@MAXMIND/Meta::Contributors' version: '0.003' - class: Dist::Zilla::Plugin::MetaConfig name: '@MAXMIND/MetaConfig' version: '6.007' - class: Dist::Zilla::Plugin::MetaJSON name: '@MAXMIND/MetaJSON' version: '6.007' - class: Dist::Zilla::Plugin::MinimumPerl name: '@MAXMIND/MinimumPerl' version: '1.006' - class: Dist::Zilla::Plugin::RewriteVersion config: Dist::Zilla::Plugin::RewriteVersion: add_tarball_name: 0 finders: - ':ExecFiles' - ':InstallModules' global: 0 skip_version_provider: 0 name: '@MAXMIND/RewriteVersion' version: '0.015' - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@MAXMIND/PodSyntaxTests' version: '6.007' - class: Dist::Zilla::Plugin::Test::CPAN::Changes config: Dist::Zilla::Plugin::Test::CPAN::Changes: changelog: Changes name: '@MAXMIND/Test::CPAN::Changes' version: '0.012' - class: Dist::Zilla::Plugin::Test::EOL config: Dist::Zilla::Plugin::Test::EOL: filename: xt/author/eol.t finder: - ':ExecFiles' - ':InstallModules' - ':TestFiles' trailing_whitespace: 1 name: '@MAXMIND/Test::EOL' version: '0.19' - class: Dist::Zilla::Plugin::Test::NoTabs config: Dist::Zilla::Plugin::Test::NoTabs: filename: xt/author/no-tabs.t finder: - ':InstallModules' - ':ExecFiles' - ':TestFiles' name: '@MAXMIND/Test::NoTabs' version: '0.15' - class: Dist::Zilla::Plugin::Test::Portability config: Dist::Zilla::Plugin::Test::Portability: options: '' name: '@MAXMIND/Test::Portability' version: '2.001000' - class: Dist::Zilla::Plugin::Test::Synopsis name: '@MAXMIND/Test::Synopsis' version: '2.000007' - class: Dist::Zilla::Plugin::Test::TidyAll name: '@MAXMIND/Test::TidyAll' version: '0.03' - class: Dist::Zilla::Plugin::Test::Version name: '@MAXMIND/Test::Version' version: '1.09' - class: Dist::Zilla::Plugin::Test::Compile config: Dist::Zilla::Plugin::Test::Compile: bail_out_on_fail: '0' fail_on_warning: author fake_home: 0 filename: xt/author/00-compile.t module_finder: - ':InstallModules' needs_display: 0 phase: develop script_finder: - ':PerlExecFiles' skips: [] name: '@MAXMIND/Test::Compile' version: '2.054' - class: Dist::Zilla::Plugin::Git::Check config: Dist::Zilla::Plugin::Git::Check: untracked_files: die Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - .mailmap - CONTRIBUTING.md - Changes - LICENSE - Makefile.PL - README.md - cpanfile allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: repo_root: . name: '@MAXMIND/Git::Check' version: '2.039' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: v%v%n%n%c Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - .mailmap - CONTRIBUTING.md - Changes - LICENSE - Makefile.PL - README.md - cpanfile allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@MAXMIND/commit generated files' version: '2.039' - class: Dist::Zilla::Plugin::Git::Tag config: Dist::Zilla::Plugin::Git::Tag: branch: ~ changelog: Changes signed: 0 tag: v0.22 tag_format: v%v tag_message: v%v Dist::Zilla::Role::Git::Repo: repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@MAXMIND/Git::Tag' version: '2.039' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - origin remotes_must_exist: 1 Dist::Zilla::Role::Git::Repo: repo_root: . name: '@MAXMIND/Git::Push' version: '2.039' - class: Dist::Zilla::Plugin::BumpVersionAfterRelease config: Dist::Zilla::Plugin::BumpVersionAfterRelease: finders: - ':ExecFiles' - ':InstallModules' global: 0 munge_makefile_pl: 1 name: '@MAXMIND/BumpVersionAfterRelease' version: '0.015' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: 'Bump version after release' Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - dist.ini allow_dirty_match: - (?^:.+) changelog: Changes Dist::Zilla::Role::Git::Repo: repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@MAXMIND/commit version bump' version: '2.039' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - origin remotes_must_exist: 1 Dist::Zilla::Role::Git::Repo: repo_root: . name: '@MAXMIND/push version bump' version: '2.039' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: '@MAXMIND/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: '6.007' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: '0' version: '6.007' x_authority: cpan:MAXMIND x_contributors: - 'Alexander Hartmaier ' - 'Dave Rolsky ' - 'Greg Oschwald ' - 'TJ Mather ' - 'William Stevenson ' x_serialization_backend: 'YAML::Tiny version 1.69' Net-Works-0.22/LICENSE0000644000175000017500000004365512756362344014164 0ustar autarchautarchThis software is copyright (c) 2016 by MaxMind, Inc. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2016 by MaxMind, Inc. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2016 by MaxMind, Inc. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Net-Works-0.22/lib/0000775000175000017500000000000012756362344013712 5ustar autarchautarchNet-Works-0.22/lib/Net/0000775000175000017500000000000012756362344014440 5ustar autarchautarchNet-Works-0.22/lib/Net/Works.pm0000644000175000017500000000653312756362344016110 0ustar autarchautarchpackage Net::Works; use strict; use warnings; use 5.010000; our $VERSION = '0.22'; 1; # ABSTRACT: Sane APIs for IP addresses and networks __END__ =pod =head1 NAME Net::Works - Sane APIs for IP addresses and networks =head1 VERSION version 0.22 =head1 DESCRIPTION The L module is very complete, correct, and useful. However, its API design is a bit crufty. This distro provides an alternative API that aims to address the biggest problems with that module's API, as well as adding some additional features. This distro contains two modules, L and L. B =head1 Net::Works VERSUS NetAddr::IP Here are some of the key differences between the two distributions: =over 4 =item * Separation of address from network C provides two classes, one for single IP addresses and one for networks (and subnets). With L a single address is represented as a /32 or /128 subnet. This is technically correct but can make the API harder to use. Whenever you want a single IP you're always stuck checking that the object you're working with is the size of a single address subnet. =item * Multiple constructors L allows you to construct an IP address from a string ("192.0.2.1") or an integer (3221225985) using separate constructors. =item * Next & previous IP You can get the next and previous address from L object, regardless of whether or not that address is in the same subnet. =item * Constructors throw exceptions If you pass bad data to a constructor you'll get an exception. =item * Sane iterator and first/last The iterator provided by L has no confusing special cases. It always returns all the addresses in a network, including the network and broadcast addresses. Similarly, the C<< $network->first() >> and C<< $network->last() >> do not return different results for different sized networks. =item * Split a range into subnets The L class provides a C<< Net::Works::Network->range_as_subnets >> method that takes a start and end IP address and splits this into a set of subnets that include all addresses in the range. =item * Does less This distro does not support every method provided by L. Patches to add more features are welcome, however. =back =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 AUTHORS =over 4 =item * Dave Rolsky =item * Greg Oschwald =item * Olaf Alders =back =head1 CONTRIBUTORS =for stopwords Alexander Hartmaier Dave Rolsky Greg Oschwald TJ Mather William Stevenson =over 4 =item * Alexander Hartmaier =item * Dave Rolsky =item * Greg Oschwald =item * TJ Mather =item * William Stevenson =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2016 by MaxMind, Inc. 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 Net-Works-0.22/lib/Net/Works/0000775000175000017500000000000012756362344015545 5ustar autarchautarchNet-Works-0.22/lib/Net/Works/Address.pm0000644000175000017500000002031012756362344017462 0ustar autarchautarchpackage Net::Works::Address; use strict; use warnings; our $VERSION = '0.22'; use Carp qw( confess ); use Math::Int128 0.06 qw( uint128 uint128_to_hex uint128_to_number ); use Net::Works::Types qw( PackedBinary Str ); use Net::Works::Util qw( _integer_address_to_binary _integer_address_to_string _string_address_to_integer _validate_ip_string ); use Scalar::Util qw( blessed ); use Socket 1.99 qw( AF_INET AF_INET6 inet_pton inet_ntop ); use integer; # Using this currently breaks overloading - see # https://rt.cpan.org/Ticket/Display.html?id=50938 # #use namespace::autoclean; use overload ( q{""} => '_overloaded_as_string', '<=>' => '_compare_overload', 'cmp' => '_compare_overload', ); use Moo; with 'Net::Works::Role::IP'; has _binary => ( is => 'ro', reader => 'as_binary', isa => PackedBinary, lazy => 1, builder => '_build_binary', ); has _string => ( is => 'ro', reader => 'as_string', isa => Str, lazy => 1, builder => '_build_string', ); sub BUILD { my $self = shift; $self->_validate_ip_integer(); return; } sub new_from_string { my $class = shift; my %p = @_; my $str = delete $p{string}; my $version = delete $p{version}; if ( defined $str && inet_pton( AF_INET, $str ) ) { $version ||= 4; $str = '::' . $str if $version == 6; } else { $version ||= 6; _validate_ip_string( $str, $version ); } return $class->new( _integer => _string_address_to_integer( $str, $version ), version => $version, %p, ); } sub new_from_integer { my $class = shift; my %p = @_; my $int = delete $p{integer}; my $version = delete $p{version}; $version ||= ref $int ? 6 : 4; return $class->new( _integer => $int, version => $version, %p, ); } sub _build_string { my $self = shift; return _integer_address_to_string( $self->_integer() ); } sub _build_binary { _integer_address_to_binary( $_[0]->as_integer() ) } sub as_integer { $_[0]->_integer() } sub as_ipv4_string { my $self = shift; return $self->as_string() if $self->version() == 4; confess 'Cannot represent IP address larger than 2**32-1 as an IPv4 string' if $self->as_integer() >= 2**32; return __PACKAGE__->new_from_integer( integer => $self->as_integer(), version => 4, )->as_string(); } sub as_bit_string { my $self = shift; if ( $self->version == 6 ) { my $hex = uint128_to_hex( $self->as_integer() ); my @ha = $hex =~ /.{8}/g; return join q{}, map { sprintf( '%032b', hex($_) ) } @ha; } else { return sprintf( '%032b', $self->as_integer() ); } } sub prefix_length { $_[0]->bits() } sub mask_length { $_[0]->prefix_length() } sub next_ip { my $self = shift; confess "$self is the last address in its range" if $self->as_integer() == $self->_max; return __PACKAGE__->new_from_integer( integer => $self->as_integer() + 1, version => $self->version(), ); } sub previous_ip { my $self = shift; confess "$self is the first address in its range" if $self->as_integer() == 0; return __PACKAGE__->new_from_integer( integer => $self->as_integer() - 1, version => $self->version(), ); } sub _compare_overload { my $self = shift; my $other = shift; my $flip = shift() ? -1 : 1; confess 'Cannot compare unless both objects are ' . __PACKAGE__ . ' objects' unless blessed $self && blessed $other && eval { $self->isa(__PACKAGE__) && $other->isa(__PACKAGE__) }; return $flip * ( $self->as_integer() <=> $other->as_integer() ); } __PACKAGE__->meta()->make_immutable(); 1; # ABSTRACT: An object representing a single IP (4 or 6) address __END__ =pod =head1 NAME Net::Works::Address - An object representing a single IP (4 or 6) address =head1 VERSION version 0.22 =head1 SYNOPSIS use Net::Works::Address; my $ip = Net::Works::Address->new_from_string( string => '192.0.2.1' ); print $ip->as_string(); # 192.0.2.1 print $ip->as_integer(); # 3221225985 print $ip->as_binary(); # 4-byte packed form of the address print $ip->as_bit_string(); # 11000000000000000000001000000001 print $ip->version(); # 4 print $ip->prefix_length(); # 32 my $next = $ip->next_ip(); # 192.0.2.2 my $prev = $ip->previous_ip(); # 192.0.2.0 if ( $next > $ip ) { print $ip->as_string(); } my @sorted = sort $next, $prev, $ip; my $ipv6 = Net::Works::Address->new_from_string( string => '2001:db8::1234' ); print $ipv6->as_integer(); # 42540766411282592856903984951653831220 my $ip_from_int = Net::Works::Address->new_from_integer( integer => "42540766411282592856903984951653831220" ); =head1 DESCRIPTION Objects of this class represent a single IP address. It can handle both IPv4 and IPv6 addresses. It provides various methods for getting information about the address, and also overloads the objects so that addresses can be compared as integers. For IPv6, it uses 128-bit integers (via Math::Int128) to represent the numeric value of an address. =head1 METHODS This class provides the following methods: =head2 Net::Works::Address->new_from_string( ... ) This method takes a C parameter and an optional C parameter. The C parameter should be a string representation of an IP address. The C parameter should be either C<4> or C<6>, but you don't really need this unless you're trying to force a dotted quad to be interpreted as an IPv6 address or to a force an IPv6 address colon-separated hex number to be interpreted as an IPv4 address. =head2 Net::Works::Address->new_from_integer( ... ) This method takes a C parameter and an optional C parameter. The C parameter should be an integer representation of an IP address. The C parameter should be either C<4> or C<6>. Unlike with strings, you'll need to set the version explicitly to get an IPv6 address. =head2 $ip->as_string() Returns a string representation of the address in the same format as inet_ntop, e.g., "192.0.2.1", "::192.0.2.1", or "2001:db8::1234". =head2 $ip->as_integer() Returns the address as an integer. For IPv6 addresses, this is returned as a L object, regardless of the value. =head2 $ip->as_binary() Returns the packed binary form of the address (4 or 16 bytes). =head2 $ip->as_bit_string() Returns the address as a string of 1's and 0's, like "00000000000000000000000000010000". =head2 $ip->as_ipv4_string() This returns a dotted quad representation of an address, even if it's an IPv6 address. However, this will die if the address is greater than the max value of an IPv4 address (2**32 - 1). It's primarily useful for debugging. =head2 $ip->version() Returns a 4 or 6 to indicate whether this is an IPv4 or IPv6 address. =head2 $ip->prefix_length() Returns the prefix length for the IP address, which is either 32 (IPv4) or 128 (IPv6). =head2 $ip->bits() An alias for C<< $ip->prefix_length() >>. This helps make addresses & network objects interchangeable in some cases. =head2 $ip->next_ip() Returns the numerically next IP, regardless of whether or not it's in the same subnet as the current IP. This will throw an error if the current IP address it the last address in its IP range. =head2 $ip->previous_ip() Returns the numerically previous IP, regardless of whether or not it's in the same subnet as the current IP. This will throw an error if the current IP address it the first address in its IP range (address 0). =head1 OVERLOADING This class overloads comparison, allowing you to compare two objects and to sort them (either as numbers or strings). It also overloads stringification to call the C<< $ip->as_string() >> method. =head1 AUTHORS =over 4 =item * Dave Rolsky =item * Greg Oschwald =item * Olaf Alders =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2016 by MaxMind, Inc. 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 Net-Works-0.22/lib/Net/Works/Types.pm0000644000175000017500000000465312756362344017215 0ustar autarchautarchpackage Net::Works::Types; use strict; use warnings; our $VERSION = '0.22'; use Carp qw( confess ); use Exporter qw( import ); use Scalar::Util (); use Sub::Quote qw( quote_sub ); our @EXPORT_OK = qw( Int IPInt IPVersion PrefixLength NetWorksAddress PackedBinary Str ); ## no critic (ValuesAndExpressions::ProhibitImplicitNewlines, NamingConventions::Capitalization) { my $t = quote_sub( q{ ( defined $_[0] && !ref $_[0] && $_[0] =~ /^[0-9]+\z/ ) or Net::Works::Types::_confess( '%s is not a valid integer for an IP address', $_[0] ); } ); sub Int () { $t } } { my $t = quote_sub( q{ ( defined $_[0] && ( ( !ref $_[0] && $_[0] =~ /^[0-9]+\z/ ) || ( Scalar::Util::blessed( $_[0] ) && ( $_[0]->isa('Math::UInt128') || $_[0]->isa('Math::BigInt') ) ) ) ) or Net::Works::Types::_confess( '%s is not a valid integer for an IP address', defined $_[0] ? $_[0] : 'undef' ); } ); sub IPInt () { $t } } { my $t = quote_sub( q{ ( defined $_[0] && !ref $_[0] && ( $_[0] == 4 || $_[0] == 6 ) ) or Net::Works::Types::_confess( '%s is not a valid IP version (4 or 6)', defined $_[0] ? $_[0] : 'undef' ); } ); sub IPVersion () { $t } } { my $t = quote_sub( q{ ( !ref $_[0] && defined $_[0] && $_[0] =~ /^[0-9]+\z/ && $_[0] <= 128 ) or Net::Works::Types::_confess( '%s is not a valid IP network prefix length (0-128)', defined $_[0] ? $_[0] : 'undef' ); } ); sub PrefixLength () { $t } } { my $t = quote_sub( q{ ( Scalar::Util::blessed( $_[0] ) && $_[0]->isa('Net::Works::Address') ) or Net::Works::Types::_confess( '%s is not a Net::Works::Address object', $_[0] ); } ); sub NetWorksAddress () { $t } } { my $t = quote_sub( q{ ( defined $_[0] && !ref $_[0] ) or Net::Works::Types::_confess( '%s is not binary data', $_[0] ); } ); sub PackedBinary () { $t } } { my $t = quote_sub( q{ ( defined $_[0] && !ref $_[0] ) or Net::Works::Types::_confess( '%s is not a string', $_[0] ); } ); sub Str () { $t } } ## use critic ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines, Variables::ProhibitPackageVars) sub _confess { local $Carp::Internal{__PACKAGE__} = 1; confess sprintf( $_[0], defined $_[1] ? $_[1] : 'undef' ); } ## use critic 1; Net-Works-0.22/lib/Net/Works/Network.pm0000644000175000017500000004543412756362344017544 0ustar autarchautarchpackage Net::Works::Network; use strict; use warnings; our $VERSION = '0.22'; use Carp qw( confess ); use List::AllUtils qw( any ); use Math::Int128 qw( uint128 ); use Net::Works::Address; use Net::Works::Types qw( IPInt PrefixLength NetWorksAddress Str ); use Net::Works::Util qw( _integer_address_to_string _string_address_to_integer ); use Scalar::Util qw( blessed ); use Socket 1.99 qw( inet_pton AF_INET AF_INET6 ); use integer; # Using this currently breaks overloading - see # https://rt.cpan.org/Ticket/Display.html?id=50938 # #use namespace::autoclean; use overload ( q{""} => '_overloaded_as_string', '<=>' => '_compare_overload', 'cmp' => '_compare_overload', ); use Moo; with 'Net::Works::Role::IP'; has first => ( is => 'ro', isa => NetWorksAddress, init_arg => undef, lazy => 1, builder => '_build_first', ); has last => ( is => 'ro', isa => NetWorksAddress, init_arg => undef, lazy => 1, builder => '_build_last', ); has prefix_length => ( is => 'ro', isa => PrefixLength, required => 1, ); has _address_string => ( is => 'ro', isa => Str, init_arg => undef, lazy => 1, builder => '_build_address_string', ); has _subnet_integer => ( is => 'ro', isa => IPInt, init_arg => undef, lazy => 1, builder => '_build_subnet_integer', ); around BUILDARGS => sub { my $orig = shift; my $class = shift; my $p = $class->$orig(@_); $p->{prefix_length} = delete $p->{mask_length} if exists $p->{mask_length}; return $p; }; sub mask_length { $_[0]->prefix_length() } sub BUILD { my $self = shift; $self->_validate_ip_integer(); my $max = $self->bits(); if ( $self->prefix_length() > $max ) { confess $self->prefix_length() . ' is not a valid IP network prefix length'; } return; } sub new_from_string { my $class = shift; my %p = @_; die 'undef is not a valid IP network' unless defined $p{string}; my ( $address, $prefix_length ) = split /\//, $p{string}, 2; my $version = $p{version} ? $p{version} : inet_pton( AF_INET6, $address ) ? 6 : 4; if ( $version == 6 && inet_pton( AF_INET, $address ) ) { $prefix_length += 96; $address = '::' . $address; } my $integer = _string_address_to_integer( $address, $version ); confess "$p{string} is not a valid IP network" unless defined $integer; return $class->new( _integer => $integer, prefix_length => $prefix_length, version => $version, ); } sub new_from_integer { my $class = shift; my %p = @_; my $integer = delete $p{integer}; my $version = delete $p{version}; $version ||= ref $integer ? 6 : 4; return $class->new( _integer => $integer, version => $version, %p, ); } sub _build_address_string { _integer_address_to_string( $_[0]->first_as_integer ); } sub _build_subnet_integer { my $self = shift; return $self->_prefix_length_to_mask( $self->prefix_length() ); } sub _prefix_length_to_mask { my $self = shift; my $prefix_length = shift; # We need to special case 0 because left shifting a 128-bit integer by 128 # bits does not produce 0. return $self->prefix_length() == 0 ? 0 : $self->_max() & ( $self->_max() << ( $self->bits - $prefix_length ) ); } sub max_prefix_length { my $self = shift; my $base = $self->first()->as_integer(); my $prefix_length = $self->prefix_length(); my $bits = $self->bits; while ($prefix_length) { my $mask = $self->_prefix_length_to_mask($prefix_length); last if ( $base & $mask ) != $base; $prefix_length--; } return $prefix_length + 1; } sub max_mask_length { $_[0]->max_prefix_length() } sub iterator { my $self = shift; my $version = $self->version(); my $current_ip = $self->first()->as_integer(); my $last_ip = $self->last()->as_integer(); return sub { return if $current_ip > $last_ip; Net::Works::Address->new_from_integer( integer => $current_ip++, version => $version, ); }; } sub as_string { my $self = shift; return join '/', lc $self->_address_string(), $self->prefix_length(); } sub _build_first { my $self = shift; my $int = $self->first_as_integer; return Net::Works::Address->new_from_integer( integer => $int, version => $self->version(), ); } sub first_as_integer { $_[0]->_integer() & $_[0]->_subnet_integer() } sub _build_last { my $self = shift; my $int = $self->last_as_integer; return Net::Works::Address->new_from_integer( integer => $int, version => $self->version(), ); } sub last_as_integer { my $self = shift; return $self->_integer() | ( $self->_max() & ~$self->_subnet_integer() ); } sub contains { my $self = shift; my $thing = shift; my $first_integer; my $last_integer; if ( $thing->isa('Net::Works::Address') ) { $first_integer = $last_integer = $thing->as_integer(); } elsif ( $thing->isa('Net::Works::Network') ) { $first_integer = $thing->first_as_integer(); $last_integer = $thing->last_as_integer(); } else { confess "$thing is not a Net::Works::Address or Net::Works::Network object"; } return $first_integer >= $self->first_as_integer() && $last_integer <= $self->last_as_integer(); } ## no critic (Subroutines::ProhibitBuiltinHomonyms) sub split { my $self = shift; return () if $self->prefix_length() == $self->bits(); my $first_int = $self->first_as_integer(); my $last_int = $self->last_as_integer(); return ( Net::Works::Network->new_from_integer( integer => $first_int, prefix_length => $self->prefix_length() + 1, ), Net::Works::Network->new_from_integer( integer => ( $first_int + ( ( $last_int - $first_int ) / 2 ) ) + 1, prefix_length => $self->prefix_length() + 1, ) ); } ## use critic sub is_single_address { my $self = shift; return ( $self->version == 4 && $self->prefix_length == 32 ) || ( $self->version == 6 && $self->prefix_length == 128 ); } sub range_as_subnets { my $class = shift; my $first_ip = shift; my $last_ip = shift; my $version = shift || ( any { /:/ } $first_ip, $last_ip ) ? 6 : 4; $first_ip = Net::Works::Address->new_from_string( string => $first_ip, version => $version, ) unless ref $first_ip; $last_ip = Net::Works::Address->new_from_string( string => $last_ip, version => $version, ) unless ref $last_ip; my @ranges = $class->_remove_reserved_subnets_from_range( $first_ip->as_integer(), $last_ip->as_integer(), $version ); my @subnets; for my $range (@ranges) { push @subnets, $class->_split_one_range( @{$range}, $version ); } return @subnets; } { my @reserved_4 = qw( 0.0.0.0/8 10.0.0.0/8 100.64.0.0/10 127.0.0.0/8 169.254.0.0/16 172.16.0.0/12 192.0.0.0/29 192.0.2.0/24 192.88.99.0/24 192.168.0.0/16 198.18.0.0/15 198.51.100.0/24 203.0.113.0/24 224.0.0.0/4 240.0.0.0/4 ); # ::/128 and ::1/128 are reserved under IPv6 but these are already covered # under 0.0.0.0/8 my @reserved_6 = ( @reserved_4, qw( 100::/64 2001::/23 2001:db8::/32 fc00::/7 fe80::/10 ff00::/8 ) ); my %reserved_networks = ( 4 => [ map { [ $_->first()->as_integer(), $_->last()->as_integer() ] } sort { $a->first <=> $b->first } map { Net::Works::Network->new_from_string( string => $_, version => 4 ) } @reserved_4, ], 6 => [ map { [ $_->first()->as_integer(), $_->last()->as_integer() ] } sort { $a->first <=> $b->first } map { Net::Works::Network->new_from_string( string => $_, version => 6 ) } @reserved_6, ], ); sub _remove_reserved_subnets_from_range { my $class = shift; my $first_ip = shift; my $last_ip = shift; my $version = shift; my @ranges; my $add_remaining = 1; for my $pn ( @{ $reserved_networks{$version} } ) { my $reserved_first = $pn->[0]; my $reserved_last = $pn->[1]; next if ( $reserved_last <= $first_ip ); last if ( $last_ip < $reserved_first ); push @ranges, [ $first_ip, $reserved_first - 1 ] if $first_ip < $reserved_first; if ( $last_ip <= $reserved_last ) { $add_remaining = 0; last; } $first_ip = $reserved_last + 1; } push @ranges, [ $first_ip, $last_ip ] if $add_remaining; return @ranges; } } sub _split_one_range { my $class = shift; my $first_ip = shift; my $last_ip = shift; my $version = shift; my @subnets; while ( $first_ip <= $last_ip ) { my $max_network = _max_subnet( $first_ip, $last_ip, $version ); push @subnets, $max_network; $first_ip = $max_network->last_as_integer + 1; } return @subnets; } sub _max_subnet { my $ip = shift; my $maxip = shift; my $version = shift; my $prefix_length = $version == 6 ? 128 : 32; my $v = $ip; my $reverse_mask = $version == 6 ? uint128(1) : 1; while (( $v & 1 ) == 0 && $prefix_length > 0 && ( $ip | $reverse_mask ) <= $maxip ) { $prefix_length--; $v = $v >> 1; $reverse_mask = ( $reverse_mask << 1 ) | 1; } return Net::Works::Network->new_from_integer( integer => $ip, prefix_length => $prefix_length, version => $version, ); } sub _compare_overload { my $self = shift; my $other = shift; confess 'Cannot compare unless both objects are ' . __PACKAGE__ . ' objects' unless blessed $self && blessed $other && eval { $self->isa(__PACKAGE__) && $other->isa(__PACKAGE__) }; my $cmp = ( $self->first() <=> $other->first() or $self->prefix_length() <=> $other->prefix_length() ); return shift() ? $cmp * -1 : $cmp; } __PACKAGE__->meta()->make_immutable(); 1; # ABSTRACT: An object representing a single IP address (4 or 6) subnet __END__ =pod =head1 NAME Net::Works::Network - An object representing a single IP address (4 or 6) subnet =head1 VERSION version 0.22 =head1 SYNOPSIS use Net::Works::Network; my $network = Net::Works::Network->new_from_string( string => '192.0.2.0/24' ); print $network->as_string(); # 192.0.2.0/24 print $network->prefix_length(); # 24 print $network->bits(); # 32 print $network->version(); # 4 my $first_address = $network->first(); print $first_address->as_string(); # 192.0.2.0 my $last_address = $network->last(); print $last_address->as_string(); # 192.0.2.255 my $iterator = $network->iterator(); while ( my $ip = $iterator->() ) { print $ip . "\n"; } my $network_32 = Net::Works::Network->new_from_string( string => '192.0.2.4/32' ); print $network_32->max_prefix_length(); # 30 # All methods work with IPv4 and IPv6 subnets my $ipv6_network = Net::Works::Network->new_from_string( string => '2001:db8::/48' ); my @subnets = Net::Works::Network->range_as_subnets( '192.0.2.1', '192.0.2.32' ); print $_->as_string, "\n" for @subnets; # 192.0.2.1/32 # 192.0.2.2/31 # 192.0.2.4/30 # 192.0.2.8/29 # 192.0.2.16/28 # 192.0.2.32/32 =head1 DESCRIPTION Objects of this class represent an IP address network. It can handle both IPv4 and IPv6 subnets. It provides various methods for getting information about the subnet. For IPv6, it uses 128-bit integers (via Math::Int128) to represent the numeric value of an address as needed. =head1 METHODS This class provides the following methods: =head2 Net::Works::Network->new_from_string( ... ) This method takes a C parameter and an optional C parameter. The C parameter should be a string representation of an IP address subnet, e.g., "192.0.2.0/24". my $network = Net::Works::Network->new_from_string( string => '192.0.2.0/24' ); print $network->as_string; # 192.0.2.0/24 The C parameter should be either C<4> or C<6>, but you don't really need this unless you're trying to force a dotted quad to be interpreted as an IPv6 network or to a force an IPv6 address colon-separated hex number to be interpreted as an IPv4 network. If you pass an IPv4 network but specify the version as C<6> then we will add 96 to the netmask. my $network = Net::Works::Network->new_from_string( string => '192.0.2.0/24', version => 6, ); print $network->as_string; # ::192.0.2.0/120 =head2 Net::Works::Network->new_from_integer( ... ) This method takes an C parameter, C parameter, and an optional C parameter. The C parameter should be an integer representation of an IP within the subnet. The C parameter should be an integer between 0 and 32 for IPv4 or 0 and 128 for IPv6. The C parameter should be either C<4> or C<6>. Note that if you are passing an IPv4 address that you want treated as an IPv6 address you need to manually add 96 to the C yourself. =head2 $network->as_string() Returns a string representation of the network like "192.0.2.0/24" or "2001:db8::/48". The IP address in the string is the first address within the subnet. =head2 $network->version() Returns a 4 or 6 to indicate whether this is an IPv4 or IPv6 network. =head2 $network->prefix_length() Returns the length of the netmask as an integer. =head2 $network->bits() Returns the number of bit of an address in the network, which is either 32 (IPv4) or 128 (IPv6). =head2 $network->max_prefix_length() This returns the maximum possible numeric subnet that this network could fit in. In other words, the 192.0.2.0/28 subnet could be part of the 192.0.2.0/23 subnet, so this returns 23. =head2 $network->first() Returns the first IP in the network as an L object. =head2 $network->first_as_integer() Returns the first IP in the network as an integer. This may be a L object. =head2 $network->last() Returns the last IP in the network as an L object. =head2 $network->last_as_integer() Returns the last IP in the network as an integer. This may be a L object. =head2 $network->is_single_address() Returns true if the network contains just a single address (/32 in IPv4 or /128 in IPv6). =head2 $network->iterator() This returns an anonymous sub that returns one IP address in the range each time it's called. For single address subnets (/32 or /128), this returns a single address. When it has exhausted all the addresses in the network, it returns C =head2 $network->contains($address_or_network) This method accepts a single L or L object. It returns true if the given address or network is contained by the network it is called on. Note that a network always contains itself. =head2 $network->split() This returns a list of two new network objects representing the original network split into two halves. For example, splitting C<192.0.2.0/24> returns C<192.0.2.0/25> and C<192.0.2.128/25>. If the original networks is a single address network (a /32 in IPv4 or /128 in IPv6) then this method returns an empty list. =head2 Net::Works::Network->range_as_subnets( $first_address, $last_address, $version ) Given two IP addresses as strings, this method breaks the range up into the largest subnets that include all the IP addresses in the range (including the two passed to this method). This method also excludes any reserved subnets such as the L IPv4 private address space, L IPv4 special-use address space and L IPv6 special-use address space. An overview can be found at the IANA L and L special-purpose address registries. The networks currently treated as reserved are: 0.0.0.0/8 10.0.0.0/8 100.64.0.0/10 127.0.0.0/8 169.254.0.0/16 172.16.0.0/12 192.0.0.0/29 192.0.2.0/24 192.88.99.0/24 192.168.0.0/16 198.18.0.0/15 198.51.100.0/24 203.0.113.0/24 224.0.0.0/4 240.0.0.0/4 100::/64 2001::/23 2001:db8::/32 fc00::/7 fe80::/10 ff00::/8 This method works with both IPv4 and IPv6 addresses. You can pass an explicit version as the final argument. If you don't, we check whether either address contains a colon (:). If either of them does, we assume you want IPv6 subnets. When given an IPv6 range that includes the first 32 bits of addresses (the IPv4 space), both IPv4 I IPv6 reserved networks are removed from the range. =head1 OVERLOADING This class overloads comparison, allowing you to compare two objects and to sort them (either as numbers or strings). Objects are compared based on the first IP address in their networks, and then by prefix length if they have the same starting address. It also overloads stringification to call the C<< $network->as_string() >> method. =head1 DEPRECATED METHODS AND ATTRIBUTES Prior to version 0.17, this package referred to the prefix length as mask length. The C and C methods are deprecated, and will probably start warning in a future release. In addition, passing a C key to the C constructor has been replaced by C. The old key will continue to work for now but may start warning in a future release. =head1 AUTHORS =over 4 =item * Dave Rolsky =item * Greg Oschwald =item * Olaf Alders =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2016 by MaxMind, Inc. 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 Net-Works-0.22/lib/Net/Works/Util.pm0000644000175000017500000000454712756362344017030 0ustar autarchautarchpackage Net::Works::Util; use strict; use warnings; our $VERSION = '0.22'; use Carp qw( confess ); use Math::Int128 qw( net_to_uint128 uint128_to_net ); use Socket qw( AF_INET AF_INET6 inet_pton inet_ntop ); use Scalar::Util qw( blessed ); use Exporter qw( import ); our @EXPORT_OK = qw( _string_address_to_integer _integer_address_to_binary _binary_address_to_string _integer_address_to_string _validate_ip_string ); ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) sub _string_address_to_integer { my $string = shift; my $version = shift; my $binary = inet_pton( $version == 4 ? AF_INET : AF_INET6, $string ) or return; return $version == 4 ? unpack( N => $binary ) : net_to_uint128($binary); } sub _integer_address_to_binary { my $integer = shift; if ( ref $integer && blessed $integer) { return uint128_to_net($integer); } else { return pack( N => $integer ); } } sub _binary_address_to_string { my $binary = shift; my $family = length($binary) == 4 ? AF_INET : AF_INET6; my $string = inet_ntop( $family, $binary ); return $string eq '::' ? '::0' : $string; } sub _integer_address_to_string { _binary_address_to_string( _integer_address_to_binary( $_[0] ) ); } sub _validate_ip_string { my $str = shift; my $version = shift; my $str_val = defined $str ? $str : 'undef'; if ( $version == 4 ) { confess("$str_val is not a valid IPv4 address") unless defined $str && defined inet_pton( AF_INET, $str ); } else { confess("$str_val is not a valid IPv6 address") unless defined $str && defined inet_pton( AF_INET6, $str ); } } 1; # ABSTRACT: Utility subroutines for Net-Works __END__ =pod =head1 NAME Net::Works::Util - Utility subroutines for Net-Works =head1 VERSION version 0.22 =head1 DESCRIPTION All of the subroutines in this module are really just for our internal use. No peeking. =head1 AUTHORS =over 4 =item * Dave Rolsky =item * Greg Oschwald =item * Olaf Alders =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2016 by MaxMind, Inc. 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 Net-Works-0.22/lib/Net/Works/Role/0000775000175000017500000000000012756362344016446 5ustar autarchautarchNet-Works-0.22/lib/Net/Works/Role/IP.pm0000644000175000017500000000314412756362344017314 0ustar autarchautarchpackage Net::Works::Role::IP; use strict; use warnings; use namespace::autoclean 0.16; our $VERSION = '0.22'; use Carp qw( confess ); use Math::Int128 qw( string_to_uint128 uint128 uint128_to_number ); use Net::Works::Types qw( Int IPInt IPVersion ); use Socket qw( AF_INET AF_INET6 ); use Moo::Role; use integer; has version => ( is => 'ro', isa => IPVersion, required => 1, ); has _integer => ( is => 'rw', writer => '_set_integer', isa => IPInt, required => 1, ); has address_family => ( is => 'ro', isa => Int, lazy => 1, default => sub { $_[0]->version() == 6 ? AF_INET6 : AF_INET }, ); { my %max = ( 4 => 0xFFFFFFFF, 6 => string_to_uint128( '0x' . ( 'F' x 32 ) ), ); sub _max { my $self = shift; my $version = shift // $self->version(); return $max{$version}; } } sub bits { $_[0]->version() == 6 ? 128 : 32 } sub _validate_ip_integer { my $self = shift; my $int = $self->_integer(); # We don't need to check if it's too big with v6 because uint128 does not # allow a number larger than 2**128-1. if ( $self->version() == 6 ) { $self->_set_integer( uint128($int) ) unless ref $int; } else { confess("$int is not a valid integer for an IP address") if $int >= 2**32; if ( ref $int ) { $self->_set_integer( uint128_to_number($int) ); } } return; } # overload passes extra arguments to this sub for some reason sub _overloaded_as_string { return $_[0]->as_string(); } 1; Net-Works-0.22/META.json0000644000175000017500000007046612756362344014600 0ustar autarchautarch{ "abstract" : "Sane APIs for IP addresses and networks", "author" : [ "Dave Rolsky ", "Greg Oschwald ", "Olaf Alders " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.007, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Net-Works", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0", "perl" : "5.010000" } }, "develop" : { "requires" : { "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Perl::Critic" : "1.123", "Perl::Tidy" : "20140711", "Pod::Coverage::Moose" : "0", "Pod::Coverage::TrustPod" : "0", "Test::CPAN::Changes" : "0.19", "Test::Code::TidyAll" : "0.24", "Test::EOL" : "0", "Test::More" : "0.88", "Test::NoTabs" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08", "Test::Portability::Files" : "0", "Test::Spelling" : "0.12", "Test::Synopsis" : "0", "Test::Version" : "1" } }, "runtime" : { "requires" : { "Carp" : "0", "Exporter" : "0", "List::AllUtils" : "0", "Math::Int128" : "0.06", "Moo" : "0", "Moo::Role" : "0", "Scalar::Util" : "0", "Socket" : "1.99", "Sub::Quote" : "0", "integer" : "0", "namespace::autoclean" : "0.16", "overload" : "0", "perl" : "5.010", "strict" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "B" : "0", "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "Math::BigInt" : "0", "Test::Fatal" : "0", "Test::More" : "0.96", "perl" : "5.010" } } }, "provides" : { "Net::Works" : { "file" : "lib/Net/Works.pm", "version" : "0.22" }, "Net::Works::Address" : { "file" : "lib/Net/Works/Address.pm", "version" : "0.22" }, "Net::Works::Network" : { "file" : "lib/Net/Works/Network.pm", "version" : "0.22" }, "Net::Works::Role::IP" : { "file" : "lib/Net/Works/Role/IP.pm", "version" : "0.22" }, "Net::Works::Types" : { "file" : "lib/Net/Works/Types.pm", "version" : "0.22" }, "Net::Works::Util" : { "file" : "lib/Net/Works/Util.pm", "version" : "0.22" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/maxmind/Net-Works/issues" }, "repository" : { "type" : "git", "url" : "git://github.com/maxmind/Net-Works.git", "web" : "https://github.com/maxmind/Net-Works" } }, "version" : "0.22", "x_Dist_Zilla" : { "perl" : { "version" : 5.020002 }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@MAXMIND/MakeMaker", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::Authority", "name" : "@MAXMIND/Authority", "version" : "1.009" }, { "class" : "Dist::Zilla::Plugin::AutoPrereqs", "name" : "@MAXMIND/AutoPrereqs", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::CopyFilesFromBuild", "name" : "@MAXMIND/CopyFilesFromBuild", "version" : "0.161350" }, { "class" : "Dist::Zilla::Plugin::Git::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [ "LICENSE", "Makefile.PL", "README.md", "cpanfile" ], "exclude_match" : [], "follow_symlinks" : 0, "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." }, "Dist::Zilla::Plugin::Git::GatherDir" : { "include_untracked" : 0 } }, "name" : "@MAXMIND/Git::GatherDir", "version" : "2.039" }, { "class" : "Dist::Zilla::Plugin::GitHub::Meta", "name" : "@MAXMIND/GitHub::Meta", "version" : "0.42" }, { "class" : "Dist::Zilla::Plugin::GitHub::Update", "config" : { "Dist::Zilla::Plugin::GitHub::Update" : { "metacpan" : 1 } }, "name" : "@MAXMIND/GitHub::Update", "version" : "0.42" }, { "class" : "Dist::Zilla::Plugin::MetaProvides::Package", "config" : { "Dist::Zilla::Plugin::MetaProvides::Package" : { "finder_objects" : [ { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@MAXMIND/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "6.007" } ], "include_underscores" : 0 }, "Dist::Zilla::Role::MetaProvider::Provider" : { "Dist::Zilla::Role::MetaProvider::Provider::VERSION" : "2.001011", "inherit_missing" : 1, "inherit_version" : 1, "meta_noindex" : 1 }, "Dist::Zilla::Role::ModuleMetadata" : { "Module::Metadata" : "1.000027", "version" : "0.004" } }, "name" : "@MAXMIND/MetaProvides::Package", "version" : "2.004002" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "@MAXMIND/NextRelease", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::Test::Pod::Coverage::Configurable", "name" : "@MAXMIND/Test::Pod::Coverage::Configurable", "version" : "0.06" }, { "class" : "Dist::Zilla::Plugin::Test::PodSpelling", "config" : { "Dist::Zilla::Plugin::Test::PodSpelling" : { "directories" : [], "spell_cmd" : "", "stopwords" : [ "API", "APIs", "Alders", "Alders'", "Eilam", "Eilam's", "Hartmaier", "IANA", "IP", "IPv", "MaxMind", "MaxMind", "MaxMind's", "Oschwald", "Oschwald", "Oschwald's", "Rolsky", "Rolsky", "Rolsky's", "TJ", "distro", "distro's", "netmask", "subnet", "subnets" ], "wordlist" : "Pod::Wordlist" } }, "name" : "@MAXMIND/Test::PodSpelling", "version" : "2.007002" }, { "class" : "Dist::Zilla::Plugin::Test::ReportPrereqs", "name" : "@MAXMIND/Test::ReportPrereqs", "version" : "0.025" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "@MAXMIND/Test::More with subtest()", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "develop", "type" : "requires" } }, "name" : "@MAXMIND/Modules for use with tidyall", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "config" : { "Dist::Zilla::Plugin::PromptIfStale" : { "check_all_plugins" : 1, "check_all_prereqs" : 1, "modules" : [], "phase" : "release", "run_under_travis" : 0, "skip" : [ "Dist::Zilla::Plugin::MAXMIND::Contributors", "Dist::Zilla::Plugin::MAXMIND::License", "Dist::Zilla::Plugin::MAXMIND::Tidyall" ] } }, "name" : "@MAXMIND/stale modules, release", "version" : "0.051" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "@MAXMIND/ReadmeMarkdownInBuild", "version" : "0.161170" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "@MAXMIND/ReadmeMarkdownInRoot", "version" : "0.161170" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@MAXMIND/UploadToCPAN", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::SurgicalPodWeaver", "config" : { "Dist::Zilla::Plugin::PodWeaver" : { "finder" : [ ":InstallModules", ":ExecFiles" ], "plugins" : [ { "class" : "Pod::Weaver::Plugin::EnsurePod5", "name" : "@CorePrep/EnsurePod5", "version" : "4.013" }, { "class" : "Pod::Weaver::Plugin::H1Nester", "name" : "@CorePrep/H1Nester", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Name", "name" : "Name", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Version", "name" : "Version", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Region", "name" : "prelude", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "SYNOPSIS", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "DESCRIPTION", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Leftovers", "name" : "Leftovers", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Region", "name" : "postlude", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Authors", "name" : "Authors", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Contributors", "name" : "Contributors", "version" : "0.009" }, { "class" : "Pod::Weaver::Section::Legal", "name" : "Legal", "version" : "4.013" } ] } }, "name" : "@MAXMIND/SurgicalPodWeaver", "version" : "0.0023" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@MAXMIND/PruneCruft", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@MAXMIND/ManifestSkip", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@MAXMIND/MetaYAML", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@MAXMIND/License", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::ExtraTests", "name" : "@MAXMIND/ExtraTests", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@MAXMIND/ExecDir", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@MAXMIND/ShareDir", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@MAXMIND/Manifest", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::CheckVersionIncrement", "name" : "@MAXMIND/CheckVersionIncrement", "version" : "0.121750" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@MAXMIND/TestRelease", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@MAXMIND/ConfirmRelease", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::CheckPrereqsIndexed", "name" : "@MAXMIND/CheckPrereqsIndexed", "version" : "0.018" }, { "class" : "Dist::Zilla::Plugin::CPANFile", "name" : "@MAXMIND/CPANFile", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch", "config" : { "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." } }, "name" : "@MAXMIND/Git::CheckFor::CorrectBranch", "version" : "0.013" }, { "class" : "Dist::Zilla::Plugin::Git::CheckFor::MergeConflicts", "config" : { "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." } }, "name" : "@MAXMIND/Git::CheckFor::MergeConflicts", "version" : "0.013" }, { "class" : "Dist::Zilla::Plugin::Git::Contributors", "config" : { "Dist::Zilla::Plugin::Git::Contributors" : { "git --version" : "2.9.3", "include_authors" : 0, "include_releaser" : 1, "order_by" : "name", "paths" : [ "." ] } }, "name" : "@MAXMIND/Git::Contributors", "version" : "0.024" }, { "class" : "Dist::Zilla::Plugin::InstallGuide", "name" : "@MAXMIND/InstallGuide", "version" : "1.200007" }, { "class" : "Dist::Zilla::Plugin::MAXMIND::Contributors", "name" : "@MAXMIND/MAXMIND::Contributors", "version" : "0.13" }, { "class" : "Dist::Zilla::Plugin::MAXMIND::License", "name" : "@MAXMIND/MAXMIND::License", "version" : "0.13" }, { "class" : "Dist::Zilla::Plugin::MAXMIND::TidyAll", "name" : "@MAXMIND/MAXMIND::TidyAll", "version" : "0.13" }, { "class" : "Dist::Zilla::Plugin::Meta::Contributors", "name" : "@MAXMIND/Meta::Contributors", "version" : "0.003" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@MAXMIND/MetaConfig", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@MAXMIND/MetaJSON", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::MinimumPerl", "name" : "@MAXMIND/MinimumPerl", "version" : "1.006" }, { "class" : "Dist::Zilla::Plugin::RewriteVersion", "config" : { "Dist::Zilla::Plugin::RewriteVersion" : { "add_tarball_name" : 0, "finders" : [ ":ExecFiles", ":InstallModules" ], "global" : 0, "skip_version_provider" : 0 } }, "name" : "@MAXMIND/RewriteVersion", "version" : "0.015" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@MAXMIND/PodSyntaxTests", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::Test::CPAN::Changes", "config" : { "Dist::Zilla::Plugin::Test::CPAN::Changes" : { "changelog" : "Changes" } }, "name" : "@MAXMIND/Test::CPAN::Changes", "version" : "0.012" }, { "class" : "Dist::Zilla::Plugin::Test::EOL", "config" : { "Dist::Zilla::Plugin::Test::EOL" : { "filename" : "xt/author/eol.t", "finder" : [ ":ExecFiles", ":InstallModules", ":TestFiles" ], "trailing_whitespace" : 1 } }, "name" : "@MAXMIND/Test::EOL", "version" : "0.19" }, { "class" : "Dist::Zilla::Plugin::Test::NoTabs", "config" : { "Dist::Zilla::Plugin::Test::NoTabs" : { "filename" : "xt/author/no-tabs.t", "finder" : [ ":InstallModules", ":ExecFiles", ":TestFiles" ] } }, "name" : "@MAXMIND/Test::NoTabs", "version" : "0.15" }, { "class" : "Dist::Zilla::Plugin::Test::Portability", "config" : { "Dist::Zilla::Plugin::Test::Portability" : { "options" : "" } }, "name" : "@MAXMIND/Test::Portability", "version" : "2.001000" }, { "class" : "Dist::Zilla::Plugin::Test::Synopsis", "name" : "@MAXMIND/Test::Synopsis", "version" : "2.000007" }, { "class" : "Dist::Zilla::Plugin::Test::TidyAll", "name" : "@MAXMIND/Test::TidyAll", "version" : "0.03" }, { "class" : "Dist::Zilla::Plugin::Test::Version", "name" : "@MAXMIND/Test::Version", "version" : "1.09" }, { "class" : "Dist::Zilla::Plugin::Test::Compile", "config" : { "Dist::Zilla::Plugin::Test::Compile" : { "bail_out_on_fail" : 0, "fail_on_warning" : "author", "fake_home" : 0, "filename" : "xt/author/00-compile.t", "module_finder" : [ ":InstallModules" ], "needs_display" : 0, "phase" : "develop", "script_finder" : [ ":PerlExecFiles" ], "skips" : [] } }, "name" : "@MAXMIND/Test::Compile", "version" : "2.054" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "config" : { "Dist::Zilla::Plugin::Git::Check" : { "untracked_files" : "die" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ ".mailmap", "CONTRIBUTING.md", "Changes", "LICENSE", "Makefile.PL", "README.md", "cpanfile" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." } }, "name" : "@MAXMIND/Git::Check", "version" : "2.039" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "v%v%n%n%c" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ ".mailmap", "CONTRIBUTING.md", "Changes", "LICENSE", "Makefile.PL", "README.md", "cpanfile" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@MAXMIND/commit generated files", "version" : "2.039" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "config" : { "Dist::Zilla::Plugin::Git::Tag" : { "branch" : null, "changelog" : "Changes", "signed" : 0, "tag" : "v0.22", "tag_format" : "v%v", "tag_message" : "v%v" }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@MAXMIND/Git::Tag", "version" : "2.039" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "origin" ], "remotes_must_exist" : 1 }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." } }, "name" : "@MAXMIND/Git::Push", "version" : "2.039" }, { "class" : "Dist::Zilla::Plugin::BumpVersionAfterRelease", "config" : { "Dist::Zilla::Plugin::BumpVersionAfterRelease" : { "finders" : [ ":ExecFiles", ":InstallModules" ], "global" : 0, "munge_makefile_pl" : 1 } }, "name" : "@MAXMIND/BumpVersionAfterRelease", "version" : "0.015" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "Bump version after release" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "dist.ini" ], "allow_dirty_match" : [ "(?^:.+)" ], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@MAXMIND/commit version bump", "version" : "2.039" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "origin" ], "remotes_must_exist" : 1 }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." } }, "name" : "@MAXMIND/push version bump", "version" : "2.039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@MAXMIND/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "6.007" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : 0 }, "version" : "6.007" } }, "x_authority" : "cpan:MAXMIND", "x_contributors" : [ "Alexander Hartmaier ", "Dave Rolsky ", "Greg Oschwald ", "TJ Mather ", "William Stevenson " ], "x_serialization_backend" : "Cpanel::JSON::XS version 3.0217" } Net-Works-0.22/tidyall.ini0000644000175000017500000000073412756362344015311 0ustar autarchautarch[PerlTidy] select = **/*.{pl,pm,t,psgi} ignore = t/00-* ignore = t/author-* ignore = t/release-* ignore = blib/**/* ignore = .build/**/* ignore = Net-Works-*/**/* argv = --profile=$ROOT/perltidyrc [PerlCritic] select = **/*.{pl,pm,t,psgi} ignore = t/00-* ignore = t/author-* ignore = t/release-* ignore = blib/**/* ignore = .build/**/* ignore = Net-Works-*/**/* argv = --profile $ROOT/perlcriticrc --program-extensions .pl --program-extensions .t --program-extensions .psgi Net-Works-0.22/Changes0000644000175000017500000001153712756362344014444 0ustar autarchautarch0.22 2016-08-21 - Added a Net::Works::Network->is_single_address method. This returns true if the network contains just one single address. Requested byAlexander Hartmaier. GH #17. 0.21 2015-04-30 - `new_from_integer` will now accept a `Math::BigInt` in addition to a `Math::UInt128` or a standard Perl integer. 0.20 2014-10-16 - Added numeric & string comparison overloading to Net::Works::Network. - Added string comparison overloading to Net::Works::Address. 0.19 2014-08-27 - Fixed validation when a string with more than one slash (/) is passed to Net::Works::Network->new_from_string. 0.18 2014-07-08 - Fixed warnings that would happen when trying to validate some bad data. This could happen if you passed a string with no slash (/) to Net::Works::Network->new_from_string. - Make all errors call Carp::confess instead of die for consistency. 0.17 2014-07-03 - The mask_length attribute (and related methods) in Net::Works::Network has been renamed to prefix_length, which is more correct and consistent with the terminology used for IPv6. The old names (and methods) are still available, but will probably start warning in a future release. Fixes GH #8. - Require namespace::autoclean 0.16+ so our classes are not inflated from Moo to Moose classes. Fixes GH #6. 0.16 2013-12-25 - The last address in the ::0/0 network was being returned as ::0 instead of ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff. - The IPv6 address ::0 is now always stringified as "::0", not "::". However, either will be parsed correctly when giving an address as a string to a constructor. 0.15 2013-12-23 - If you passed a Math::Int128 number to Net::Works::Network->new_from_integer and specified the ip version as 4, the object would still stringify as IPv6. 0.14 2013-12-17 - Docs were changed to only use IPv4 and IPv6 addresses from the documentation address space in the docs. (Alexander Hartmaier) - Net::Works::Network objects now overload stringification. (Alexander Hartmaier) - Added more reserved IPv4 and IPv6 networks to be removed from a given IP range and included a list of all such networks in the docs. 0.13 2013-08-22 - Added two new Net::Works::Network methods: $network->contains() and $network->split(). 0.12 2013-07-10 - Converted to use Moo instead of Moose. - Switched bugtracker to GitHub. 0.11 2013-06-24 - Added $network->first_as_integer() and ->last_as_integer() methods. This is an optimization so you don't have to write $network->first()->as_integer(). Internally, the latter just turns an integer into a Net::Works::Address object that you then get the same integer out of. 0.10 2013-06-20 - The Net::Works::Network->range_as_subnets() method now takes a version parameter so you can explicitly ask for IPv4 or IPv6. - Also fixed the license in the docs to match the LICENSE file in the repo (same as Perl 5). 0.09 2013-02-06 - Documentation fixes 0.08 2013-02-04 - Fixed type constraints so they inline. 0.07 2012-12-11 - Removed all use of Data::Validate::IP and NetAddr::IP::Util. - Validate all data passed to the constructor. 0.06 2012-12-07 - Require Socket 1.99+. This fixes test failures with old version of Socket that don't provide inet_ntop or inet_pton. 0.05 2012-12-07 - More internals rewrites for the sake of speed. We now use Math::Int128 instead of Math::BigInt. The former is way faster. - Net::Works::Network now has two constructors, new_from_string() and new_from_integer(), just like Net::Works::Address. The new() method should no longer be used. 0.04 2012-12-04 - Speed improvements for Net::Works::Network->range_as_subnets(). For most use cases this won't matter but for our use at MaxMind we end up calling this a lot so making it faster is a big win. 0.03 2012-12-04 - Work around a bug in Data::Validate::IP's is_ipv6 sub. It doesn't think '::' is a valid IPv6 address. If you created a Net::Works::Network object with this address it would treat it as an IPv4 address unless you explicitly specified the version. 0.02 2012-12-03 - All changes in this release come from Greg Oschwald. - Major internals rewrite to speed things up. We no longer wrap NetAddr::IP objects (but we do use NetAddr::IP::Util). - Net::Works::Network->mask_length() now returns the mask as passed to the constructor, not the number of bits in the mask. The ->bits method returns the number of bits in the mask (32 or 128). - The Network->netmask_as_integer() method no longer exists (use mask_length() instead). The ->max_netmask_as_integer() method has been renamed to ->max_mask_length(). - Added Net::Works::Address->mask_length() and ->bits() (which always return the same thing). - We use Socket::inet_ntop to stringify addresses. 0.01 2012-11-28 - First release upon an unsuspecting world. Net-Works-0.22/MANIFEST0000644000175000017500000000125512756362344014276 0ustar autarchautarch# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.007. Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README.md cpanfile dist.ini lib/Net/Works.pm lib/Net/Works/Address.pm lib/Net/Works/Network.pm lib/Net/Works/Role/IP.pm lib/Net/Works/Types.pm lib/Net/Works/Util.pm perlcriticrc perltidyrc t/00-report-prereqs.dd t/00-report-prereqs.t t/Address.t t/Network-splitting.t t/Network.t t/author-00-compile.t t/author-eol.t t/author-no-tabs.t t/author-pod-coverage.t t/author-pod-spell.t t/author-pod-syntax.t t/author-portability.t t/author-synopsis.t t/author-test-version.t t/bad-data.t t/release-cpan-changes.t t/release-tidyall.t tidyall.ini Net-Works-0.22/perlcriticrc0000644000175000017500000000433012756362344015552 0ustar autarchautarchseverity = 3 verbose = 11 theme = core + pbp + bugs + maintenance + cosmetic + complexity + security + tests + moose exclude = Subroutines::ProhibitCallsToUndeclaredSubs [BuiltinFunctions::ProhibitStringySplit] severity = 3 [CodeLayout::RequireTrailingCommas] severity = 3 [ControlStructures::ProhibitCStyleForLoops] severity = 3 [InputOutput::RequireCheckedSyscalls] functions = :builtins exclude_functions = sleep severity = 3 [Moose::RequireCleanNamespace] modules = Moose Moose::Role MooseX::Role::Parameterized Moose::Util::TypeConstraints cleaners = namespace::autoclean [NamingConventions::Capitalization] package_exemptions = [A-Z]\w+|minFraud file_lexical_variables = [A-Z]\w+|[^A-Z]+ global_variables = :starts_with_upper scoped_lexical_variables = [A-Z]\w+|[^A-Z]+ severity = 3 # Given our code base, leaving this at 5 would be a huge pain [Subroutines::ProhibitManyArgs] max_arguments = 10 [RegularExpressions::ProhibitComplexRegexes] max_characters = 200 [RegularExpressions::ProhibitUnusualDelimiters] severity = 3 [Subroutines::ProhibitUnusedPrivateSubroutines] private_name_regex = _(?!build)\w+ skip_when_using = Moo::Role Moose::Role MooseX::Role::Parameterized Role::Tiny Test::Class::Moose::Role [TestingAndDebugging::ProhibitNoWarnings] allow = redefine [ValuesAndExpressions::ProhibitEmptyQuotes] severity = 3 [ValuesAndExpressions::ProhibitInterpolationOfLiterals] severity = 3 [ValuesAndExpressions::RequireUpperCaseHeredocTerminator] severity = 3 [Variables::ProhibitPackageVars] add_packages = Test::Builder [TestingAndDebugging::RequireUseStrict] [TestingAndDebugging::RequireUseWarnings] [-ControlStructures::ProhibitCascadingIfElse] [-ErrorHandling::RequireCarping] [-InputOutput::RequireBriefOpen] [-ValuesAndExpressions::ProhibitConstantPragma] # No need for /xsm everywhere [-RegularExpressions::RequireDotMatchAnything] [-RegularExpressions::RequireExtendedFormatting] [-RegularExpressions::RequireLineBoundaryMatching] # http://stackoverflow.com/questions/2275317/why-does-perlcritic-dislike-using-shift-to-populate-subroutine-variables [-Subroutines::RequireArgUnpacking] [-Subroutines::RequireFinalReturn] # "use v5.14" is more readable than "use 5.014" [-ValuesAndExpressions::ProhibitVersionStrings] Net-Works-0.22/INSTALL0000644000175000017500000000215612756362344014177 0ustar autarchautarchThis is the Perl distribution Net-Works. Installing Net-Works is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm Net::Works If it does not have permission to install modules to the current perl, cpanm will automatically set up and install to a local::lib in your home directory. See the local::lib documentation (https://metacpan.org/pod/local::lib) for details on enabling it in your environment. ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan Net::Works ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Makefile.PL % make && make test Then install it: % make install If your perl is system-managed, you can create a local::lib in your home directory to install modules to. For details, see the local::lib documentation: https://metacpan.org/pod/local::lib ## Documentation Net-Works documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc Net::Works Net-Works-0.22/README.md0000644000175000017500000000653412756362344014431 0ustar autarchautarch# NAME Net::Works - Sane APIs for IP addresses and networks # VERSION version 0.22 # DESCRIPTION The [NetAddr::IP](https://metacpan.org/pod/NetAddr::IP) module is very complete, correct, and useful. However, its API design is a bit crufty. This distro provides an alternative API that aims to address the biggest problems with that module's API, as well as adding some additional features. This distro contains two modules, [Net::Works::Address](https://metacpan.org/pod/Net::Works::Address) and [Net::Works::Network](https://metacpan.org/pod/Net::Works::Network). **NOTE: This distro's APIs are still in flux. Use at your own risk.** # Net::Works VERSUS NetAddr::IP Here are some of the key differences between the two distributions: - Separation of address from network `Net::Works` provides two classes, one for single IP addresses and one for networks (and subnets). With [NetAddr::IP](https://metacpan.org/pod/NetAddr::IP) a single address is represented as a /32 or /128 subnet. This is technically correct but can make the API harder to use. Whenever you want a single IP you're always stuck checking that the object you're working with is the size of a single address subnet. - Multiple constructors [Net::Works](https://metacpan.org/pod/Net::Works) allows you to construct an IP address from a string ("192.0.2.1") or an integer (3221225985) using separate constructors. - Next & previous IP You can get the next and previous address from [Net::Works::Address](https://metacpan.org/pod/Net::Works::Address) object, regardless of whether or not that address is in the same subnet. - Constructors throw exceptions If you pass bad data to a constructor you'll get an exception. - Sane iterator and first/last The iterator provided by [Net::Works::Network](https://metacpan.org/pod/Net::Works::Network) has no confusing special cases. It always returns all the addresses in a network, including the network and broadcast addresses. Similarly, the `$network->first()` and `$network->last()` do not return different results for different sized networks. - Split a range into subnets The [Net::Works::Network](https://metacpan.org/pod/Net::Works::Network) class provides a `Net::Works::Network->range_as_subnets` method that takes a start and end IP address and splits this into a set of subnets that include all addresses in the range. - Does less This distro does not support every method provided by [NetAddr::IP](https://metacpan.org/pod/NetAddr::IP). Patches to add more features are welcome, however. # BUGS Please report any bugs or feature requests to `bug-net-works@rt.cpan.org`, or through the web interface at [http://rt.cpan.org](http://rt.cpan.org). I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. # AUTHORS - Dave Rolsky - Greg Oschwald - Olaf Alders # CONTRIBUTORS - Alexander Hartmaier - Dave Rolsky - Greg Oschwald - TJ Mather - William Stevenson # COPYRIGHT AND LICENSE This software is copyright (c) 2016 by MaxMind, Inc. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.