Code Monkey home page Code Monkey logo

net-works's People

Contributors

2shortplanks avatar abraxxa avatar horgh avatar jraspass avatar oschwald avatar skybluecircles avatar tjmather avatar ugexe avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

net-works's Issues

Use documentation IP address ranges in docs

For IPv4 RFC5737 defines the blocks 192.0.2.0/24 (TEST-NET-1), 198.51.100.0/24 (TEST-NET-2) and 203.0.113.0/24 (TEST-NET-3).

For IPv6 RFC3849 defines the prefix 2001:db8::/32.

dotted-quad support for IPv4 subnet masks

I have to work with a product that returns IPv4 networks with the subnet mask in dotted-quad notation and need to parse those.
Can we add support for in- and output of this format without breaking things?

Thanks!

Use of __PACKAGE_ in Net::Works::Address breaks

This issue affects inheritance for

  • as_ipv4_string
  • previous_ip
  • next_ip

below is the test code snippet that demonstrates the issue

#####################
{
{
package Foo;
use base qw(Net::Works::Address);
}

TODO: {

    my $ip = Foo->new_from_string( string => '1.2.3.4' );

    my $next = $ip->next_ip();
    isa_ok(
        $next,
        'Foo',
        'return object of child class for value of ->next_ip'
    );


    my $prev = $ip->previous_ip();
    isa_ok(
        $prev,
        'Foo',
        'return object of child class for value of ->previous_ip'
    );


}

}
######################

This was noticed during a cv-library pull-request

networks with invalid address/subnet mask combinations are auto-fixed

I expected this to die:

my $net = Net::Works::Network->new_from_string( string => '192.0.2.1/24' );

Instead it automagically changes the object to 192.0.2.0/24 which is neither documented nor enables a user to detect such cases.

I'm using it to validate user input, with NetAddr::IP my code looks like this:

unless ( $netaddr_obj->addr eq $netaddr_obj->network->addr ) {}

which I tried to recreate using Net::Works.

Benchmarks currently show that Net::Works is approximately half as fast as NetAddr::IP which isn't bad without XS.

Tests not passed on Alpine linux

I try to install Net::Works::Address inside alpine based docker image, but it failed:

build.log:

cpanm (App::cpanminus) 1.7044 on perl 5.026003 built for x86_64-linux-thread-multi
Work directory is /root/.cpanm/work/1559638667.26004
You have make /usr/bin/make
You have /usr/bin/wget
You have /bin/tar: tar (busybox) 1.29.3
You have /usr/bin/unzip
Searching install () on cpanmetadb ...
install is up to date. (0.01)
Searching Net::Works::Address () on cpanmetadb ...
--> Working on Net::Works::Address
Fetching http://www.cpan.org/authors/id/M/MA/MAXMIND/Net-Works-0.22.tar.gz
-> OK
Unpacking Net-Works-0.22.tar.gz
Entering Net-Works-0.22
Checking configure dependencies from META.json
Checking if you have ExtUtils::MakeMaker 6.58 ... Yes (7.24)
Configuring Net-Works-0.22
Running Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Net::Works
Writing MYMETA.yml and MYMETA.json
-> OK
Checking dependencies from MYMETA.json ...
Checking if you have File::Spec 0 ... Yes (3.67)
Checking if you have Sub::Quote 0 ... Yes (2.006003)
Checking if you have Moo::Role 0 ... Yes (2.003004)
Checking if you have strict 0 ... Yes (1.11)
Checking if you have Carp 0 ... Yes (1.42)
Checking if you have Exporter 0 ... Yes (5.72)
Checking if you have Test::Fatal 0 ... Yes (0.014)
Checking if you have Moo 0 ... Yes (2.003004)
Checking if you have integer 0 ... Yes (1.01)
Checking if you have overload 0 ... Yes (1.28)
Checking if you have ExtUtils::MakeMaker 0 ... Yes (7.24)
Checking if you have Test::More 0.96 ... Yes (1.302164)
Checking if you have Socket 1.99 ... Yes (2.020_03)
Checking if you have Scalar::Util 0 ... Yes (1.46_02)
Checking if you have warnings 0 ... Yes (1.37)
Checking if you have List::AllUtils 0 ... Yes (0.15)
Checking if you have namespace::autoclean 0.16 ... Yes (0.28)
Checking if you have Math::BigInt 0 ... Yes (1.999806)
Checking if you have B 0 ... Yes (1.68)
Checking if you have Math::Int128 0.06 ... Yes (0.22)
Building and testing Net-Works-0.22
cp lib/Net/Works/Network.pm blib/lib/Net/Works/Network.pm
cp lib/Net/Works/Address.pm blib/lib/Net/Works/Address.pm
cp lib/Net/Works.pm blib/lib/Net/Works.pm
cp lib/Net/Works/Role/IP.pm blib/lib/Net/Works/Role/IP.pm
cp lib/Net/Works/Util.pm blib/lib/Net/Works/Util.pm
cp lib/Net/Works/Types.pm blib/lib/Net/Works/Types.pm
Manifying 4 pod documents
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
# 
# Versions for all modules listed in MYMETA.json (including optional ones):
# 
# === Configure Requires ===
# 
#     Module              Want Have
#     ------------------- ---- ----
#     ExtUtils::MakeMaker  any 7.24
# 
# === Build Requires ===
# 
#     Module              Want Have
#     ------------------- ---- ----
#     ExtUtils::MakeMaker  any 7.24
# 
# === Test Requires ===
# 
#     Module              Want     Have
#     ------------------- ---- --------
#     B                    any     1.68
#     ExtUtils::MakeMaker  any     7.24
#     File::Spec           any     3.67
#     Math::BigInt         any 1.999806
#     Test::Fatal          any    0.014
#     Test::More          0.96 1.302164
# 
# === Test Recommends ===
# 
#     Module         Want     Have
#     ---------- -------- --------
#     CPAN::Meta 2.120900 2.150010
# 
# === Runtime Requires ===
# 
#     Module               Want     Have
#     -------------------- ---- --------
#     Carp                  any     1.42
#     Exporter              any     5.72
#     List::AllUtils        any     0.15
#     Math::Int128         0.06     0.22
#     Moo                   any 2.003004
#     Moo::Role             any 2.003004
#     Scalar::Util          any  1.46_02
#     Socket               1.99 2.020_03
#     Sub::Quote            any 2.006003
#     integer               any     1.01
#     namespace::autoclean 0.16     0.28
#     overload              any     1.28
#     strict                any     1.11
#     warnings              any     1.37
# 
t/00-report-prereqs.t ..... ok

#   Failed test 'address objects sort numerically'
#   at t/Address.t line 97.
#     Structures begin differing at:
#          $got->[0] = '::102:304'
#     $expected->[0] = '::1.2.3.4'

#   Failed test 'address objects sort alphabetically'
#   at t/Address.t line 103.
#     Structures begin differing at:
#          $got->[0] = '::102:304'
#     $expected->[0] = '::1.2.3.4'

#   Failed test 'new_from_integer(2**32 - 1), IPv6'
#   at t/Address.t line 254.
#          got: '::ffff:ffff'
#     expected: '::255.255.255.255'
# Looks like you failed 3 tests of 41.
t/Address.t ............... 
Dubious, test returned 3 (wstat 768, 0x300)
Failed 3/41 subtests 
t/author-00-compile.t ..... skipped: these tests are for testing by the author
t/author-eol.t ............ skipped: these tests are for testing by the author
t/author-no-tabs.t ........ skipped: these tests are for testing by the author
t/author-pod-coverage.t ... skipped: these tests are for testing by the author
t/author-pod-spell.t ...... skipped: these tests are for testing by the author
t/author-pod-syntax.t ..... skipped: these tests are for testing by the author
t/author-portability.t .... skipped: these tests are for testing by the author
t/author-synopsis.t ....... skipped: these tests are for testing by the author
t/author-test-version.t ... skipped: these tests are for testing by the author
t/bad-data.t .............. ok
t/Network-splitting.t ..... ok

#   Failed test 'network objects sort numerically'
#   at t/Network.t line 129.
#     Structures begin differing at:
#          $got->[0] = '::102:300/124'
#     $expected->[0] = '::1.2.3.0/124'

#   Failed test 'network objects sort alphabetically'
#   at t/Network.t line 135.
#     Structures begin differing at:
#          $got->[0] = '::102:300/124'
#     $expected->[0] = '::1.2.3.0/124'
# Looks like you failed 2 tests of 367.
t/Network.t ............... 
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/367 subtests 
t/release-cpan-changes.t .. skipped: these tests are for release candidate testing
t/release-tidyall.t ....... skipped: these tests are for release candidate testing

Test Summary Report
-------------------
t/Address.t             (Wstat: 768 Tests: 41 Failed: 3)
  Failed tests:  11-12, 31
  Non-zero exit status: 3
t/Network.t             (Wstat: 512 Tests: 367 Failed: 2)
  Failed tests:  16-17
  Non-zero exit status: 2
Files=16, Tests=1474,  1 wallclock secs ( 0.13 usr  0.01 sys +  0.96 cusr  0.08 csys =  1.18 CPU)
Result: FAIL
Failed 2/16 test programs. 5/1474 subtests failed.
make: *** [Makefile:901: test_dynamic] Error 255
-> FAIL Installing Net::Works::Address failed. See /root/.cpanm/work/1559638667.26004/build.log for details. Retry with --force to force install it.

on debian:

perl -e 'use Net::Works::Address; print(Net::Works::Address->new_from_string(string => "::1.2.3.4")->as_string())'
::1.2.3.4

on alpine:

perl -e 'use Net::Works::Address; print(Net::Works::Address->new_from_string(string => "::1.2.3.4")->as_string());'
::102:304

Tests are not passed under windows

Env: strawberry per 5.22.0 x64

"D:\devel\perl\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t/*.t
t/00-compile.t ............ ok
t/00-report-prereqs.t ..... #
# Versions for all modules listed in MYMETA.json (including optional ones):
#
# === Configure Requires ===
#
#     Module              Want    Have
#     ------------------- ---- -------
#     ExtUtils::MakeMaker  any 7.04_01
#
# === Build Requires ===
#
#     Module              Want    Have
#     ------------------- ---- -------
#     ExtUtils::MakeMaker  any 7.04_01
#
# === Test Requires ===
#
#     Module              Want     Have
#     ------------------- ---- --------
#     B                    any     1.58
#     ExtUtils::MakeMaker  any  7.04_01
#     File::Spec           any     3.60
#     IO::Handle           any     1.35
#     IPC::Open3           any     1.18
#     Math::BigInt         any 1.999710
#     Test::Fatal          any    0.014
#     Test::More          0.96 1.001014
#
# === Test Recommends ===
#
#     Module         Want     Have
#     ---------- -------- --------
#     CPAN::Meta 2.120900 2.150005
#
# === Runtime Requires ===
#
#     Module               Want     Have
#     -------------------- ---- --------
#     Carp                  any     1.38
#     Exporter              any     5.72
#     List::AllUtils        any     0.09
#     Math::Int128         0.06     0.22
#     Moo                   any 2.000002
#     Moo::Role             any 2.000002
#     Scalar::Util          any     1.42
#     Socket               1.99    2.021
#     Sub::Quote            any 2.000002
#     integer               any     1.01
#     namespace::autoclean 0.16     0.28
#     overload              any     1.26
#     strict                any     1.09
#     warnings              any     1.32
#
t/00-report-prereqs.t ..... ok
t/Address.t ............... ok
t/author-eol.t ............ skipped: these tests are for testing by the author
t/author-no-tabs.t ........ skipped: these tests are for testing by the author
t/author-pod-spell.t ...... skipped: these tests are for testing by the author
t/bad-data.t .............. 1/?
#   Failed test 'Net::Works::Address->new_from_string() died with 1.1 as string (v4)'
#   at t/bad-data.t line 85.
#                   undef
#     doesn't match '(?^:1\.1\ is\ not\ a\ valid\ IPv4\ address)'

#   Failed test 'Net::Works::Network->new_from_string() died with 1.1/20 as string (v4)'
#   at t/bad-data.t line 97.
#                   undef
#     doesn't match '(?^:1\.1\/20\ is\ not\ a\ valid\ IP\ network)'

#   Failed test 'Net::Works::Address->new_from_string() died with 1.1 as string (v4)'
#   at t/bad-data.t line 118.
#                   'The new() method for Net::Works::Address expects a hash reference or a key/value list. You passed an odd number of arguments
# '
#     doesn't match '(?^:1\.1\ is\ not\ a\ valid\ IPv6\ address)'
# Looks like you failed 3 tests of 74.
t/bad-data.t .............. Dubious, test returned 3 (wstat 768, 0x300)
Failed 3/74 subtests
t/Network-splitting.t ..... ok
t/Network.t ............... ok
t/release-cpan-changes.t .. skipped: these tests are for release candidate testing
t/release-pod-coverage.t .. skipped: these tests are for release candidate testing
t/release-pod-syntax.t .... skipped: these tests are for release candidate testing
t/release-portability.t ... skipped: these tests are for release candidate testing
t/release-synopsis.t ...... skipped: these tests are for release candidate testing
t/release-test-version.t .. skipped: these tests are for release candidate testing
t/release-tidyall.t ....... skipped: these tests are for release candidate testing

Test Summary Report
-------------------
t/bad-data.t            (Wstat: 768 Tests: 74 Failed: 3)
  Failed tests:  27-28, 41
  Non-zero exit status: 3
Files=16, Tests=1468,  5 wallclock secs ( 0.31 usr +  0.08 sys =  0.39 CPU)
Result: FAIL
Failed 1/16 test programs. 3/1468 subtests failed.
dmake.exe:  Error code 255, while making 'test_dynamic'
FAIL

Network stringification

I'd like to start a discussion about how ::Network objects should stringify in case they are in fact addresses (/32 for IPv4 and /128 for IPv6).
We use ::Network objects for attributes that can be networks but also addresses.
Adding another class for that mixed case would be an option as well as changing the stringification of network objects to remove the subnet mask if all bits are set.
What are your opinions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.