Skip to content

Commit ade33ed

Browse files
committed
initial release of the Perl 6 version of Net::IP
0 parents  commit ade33ed

File tree

12 files changed

+1019
-0
lines changed

12 files changed

+1019
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Net-IP.md
2+
Net-IP.1
3+
Net-IP.pdf
4+
README.md
5+
lib/.precomp/

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: perl6
2+
3+
perl6:
4+
- latest
5+
6+
install:
7+
- rakudobrew build zef
8+
- zef --deps-only install .

LICENSE

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
The Artistic License 2.0
2+
3+
Copyright (c) 2000-2006, The Perl Foundation.
4+
5+
Everyone is permitted to copy and distribute verbatim copies
6+
of this license document, but changing it is not allowed.
7+
8+
Preamble
9+
10+
This license establishes the terms under which a given free software
11+
Package may be copied, modified, distributed, and/or redistributed.
12+
The intent is that the Copyright Holder maintains some artistic
13+
control over the development of that Package while still keeping the
14+
Package available as open source and free software.
15+
16+
You are always permitted to make arrangements wholly outside of this
17+
license directly with the Copyright Holder of a given Package. If the
18+
terms of this license do not permit the full use that you propose to
19+
make of the Package, you should contact the Copyright Holder and seek
20+
a different licensing arrangement.
21+
22+
Definitions
23+
24+
"Copyright Holder" means the individual(s) or organization(s)
25+
named in the copyright notice for the entire Package.
26+
27+
"Contributor" means any party that has contributed code or other
28+
material to the Package, in accordance with the Copyright Holder's
29+
procedures.
30+
31+
"You" and "your" means any person who would like to copy,
32+
distribute, or modify the Package.
33+
34+
"Package" means the collection of files distributed by the
35+
Copyright Holder, and derivatives of that collection and/or of
36+
those files. A given Package may consist of either the Standard
37+
Version, or a Modified Version.
38+
39+
"Distribute" means providing a copy of the Package or making it
40+
accessible to anyone else, or in the case of a company or
41+
organization, to others outside of your company or organization.
42+
43+
"Distributor Fee" means any fee that you charge for Distributing
44+
this Package or providing support for this Package to another
45+
party. It does not mean licensing fees.
46+
47+
"Standard Version" refers to the Package if it has not been
48+
modified, or has been modified only in ways explicitly requested
49+
by the Copyright Holder.
50+
51+
"Modified Version" means the Package, if it has been changed, and
52+
such changes were not explicitly requested by the Copyright
53+
Holder.
54+
55+
"Original License" means this Artistic License as Distributed with
56+
the Standard Version of the Package, in its current version or as
57+
it may be modified by The Perl Foundation in the future.
58+
59+
"Source" form means the source code, documentation source, and
60+
configuration files for the Package.
61+
62+
"Compiled" form means the compiled bytecode, object code, binary,
63+
or any other form resulting from mechanical transformation or
64+
translation of the Source form.
65+
66+
67+
Permission for Use and Modification Without Distribution
68+
69+
(1) You are permitted to use the Standard Version and create and use
70+
Modified Versions for any purpose without restriction, provided that
71+
you do not Distribute the Modified Version.
72+
73+
74+
Permissions for Redistribution of the Standard Version
75+
76+
(2) You may Distribute verbatim copies of the Source form of the
77+
Standard Version of this Package in any medium without restriction,
78+
either gratis or for a Distributor Fee, provided that you duplicate
79+
all of the original copyright notices and associated disclaimers. At
80+
your discretion, such verbatim copies may or may not include a
81+
Compiled form of the Package.
82+
83+
(3) You may apply any bug fixes, portability changes, and other
84+
modifications made available from the Copyright Holder. The resulting
85+
Package will still be considered the Standard Version, and as such
86+
will be subject to the Original License.
87+
88+
89+
Distribution of Modified Versions of the Package as Source
90+
91+
(4) You may Distribute your Modified Version as Source (either gratis
92+
or for a Distributor Fee, and with or without a Compiled form of the
93+
Modified Version) provided that you clearly document how it differs
94+
from the Standard Version, including, but not limited to, documenting
95+
any non-standard features, executables, or modules, and provided that
96+
you do at least ONE of the following:
97+
98+
(a) make the Modified Version available to the Copyright Holder
99+
of the Standard Version, under the Original License, so that the
100+
Copyright Holder may include your modifications in the Standard
101+
Version.
102+
103+
(b) ensure that installation of your Modified Version does not
104+
prevent the user installing or running the Standard Version. In
105+
addition, the Modified Version must bear a name that is different
106+
from the name of the Standard Version.
107+
108+
(c) allow anyone who receives a copy of the Modified Version to
109+
make the Source form of the Modified Version available to others
110+
under
111+
112+
(i) the Original License or
113+
114+
(ii) a license that permits the licensee to freely copy,
115+
modify and redistribute the Modified Version using the same
116+
licensing terms that apply to the copy that the licensee
117+
received, and requires that the Source form of the Modified
118+
Version, and of any works derived from it, be made freely
119+
available in that license fees are prohibited but Distributor
120+
Fees are allowed.
121+
122+
123+
Distribution of Compiled Forms of the Standard Version
124+
or Modified Versions without the Source
125+
126+
(5) You may Distribute Compiled forms of the Standard Version without
127+
the Source, provided that you include complete instructions on how to
128+
get the Source of the Standard Version. Such instructions must be
129+
valid at the time of your distribution. If these instructions, at any
130+
time while you are carrying out such distribution, become invalid, you
131+
must provide new instructions on demand or cease further distribution.
132+
If you provide valid instructions or cease distribution within thirty
133+
days after you become aware that the instructions are invalid, then
134+
you do not forfeit any of your rights under this license.
135+
136+
(6) You may Distribute a Modified Version in Compiled form without
137+
the Source, provided that you comply with Section 4 with respect to
138+
the Source of the Modified Version.
139+
140+
141+
Aggregating or Linking the Package
142+
143+
(7) You may aggregate the Package (either the Standard Version or
144+
Modified Version) with other packages and Distribute the resulting
145+
aggregation provided that you do not charge a licensing fee for the
146+
Package. Distributor Fees are permitted, and licensing fees for other
147+
components in the aggregation are permitted. The terms of this license
148+
apply to the use and Distribution of the Standard or Modified Versions
149+
as included in the aggregation.
150+
151+
(8) You are permitted to link Modified and Standard Versions with
152+
other works, to embed the Package in a larger work of your own, or to
153+
build stand-alone binary or bytecode versions of applications that
154+
include the Package, and Distribute the result without restriction,
155+
provided the result does not expose a direct interface to the Package.
156+
157+
158+
Items That are Not Considered Part of a Modified Version
159+
160+
(9) Works (including, but not limited to, modules and scripts) that
161+
merely extend or make use of the Package, do not, by themselves, cause
162+
the Package to be a Modified Version. In addition, such works are not
163+
considered parts of the Package itself, and are not subject to the
164+
terms of this license.
165+
166+
167+
General Provisions
168+
169+
(10) Any use, modification, and distribution of the Standard or
170+
Modified Versions is governed by this Artistic License. By using,
171+
modifying or distributing the Package, you accept this license. Do not
172+
use, modify, or distribute the Package, if you do not accept this
173+
license.
174+
175+
(11) If your Modified Version has been derived from a Modified
176+
Version made by someone other than you, you are nevertheless required
177+
to ensure that your Modified Version complies with the requirements of
178+
this license.
179+
180+
(12) This license does not grant you the right to use any trademark,
181+
service mark, tradename, or logo of the Copyright Holder.
182+
183+
(13) This license includes the non-exclusive, worldwide,
184+
free-of-charge patent license to make, have made, use, offer to sell,
185+
sell, import and otherwise transfer the Package with respect to any
186+
patent claims licensable by the Copyright Holder that are necessarily
187+
infringed by the Package. If you institute patent litigation
188+
(including a cross-claim or counterclaim) against any party alleging
189+
that the Package constitutes direct or contributory patent
190+
infringement, then this Artistic License to you shall terminate on the
191+
date that such litigation is filed.
192+
193+
(14) Disclaimer of Warranty:
194+
THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
195+
IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
196+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
197+
NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL
198+
LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL
199+
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
200+
DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF
201+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

META6.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"perl" : "6.*",
3+
"name" : "Net::IP",
4+
"version" : "1.0.0",
5+
"description" : "Provides utility functions for dealing with IPv4 and IPv6 addresses.",
6+
"auth" : "github:tbrowder",
7+
"author" : "github:tbrowder",
8+
"authors" : [ "Tom Browder <tom.browder@gmail.com>" ],
9+
"license" : "Artistic-2.0",
10+
"source-url" : "https://github.com/tbrowder/Net-IP-Perl6.git",
11+
"support" : {
12+
"bugtracker" : "https://github.com/tbrowder/Net-IP-Perl6/issues"
13+
},
14+
"provides" : {
15+
"Net::IP" : "lib/Net/IP.pm6"
16+
},
17+
"test-depends" : [
18+
"Test::META"
19+
],
20+
"depends" : [
21+
"Number::More",
22+
"Text::More"
23+
],
24+
"resources" : [
25+
],
26+
"tags" : [
27+
"Net", "IP", "IP address", "IPv4", "IPv6", "CPAN5"
28+
]
29+
}

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
PERL6 := perl6
2+
# note LIBPATH uses normal PERL6LIB Perl 6 separators (',')
3+
LIBPATH := lib
4+
5+
# set below to 1 for no effect, 1 for debugging messages
6+
DEBUG := MyMODULE_DEBUG=0
7+
8+
# set below to 0 for no effect, 1 to die on first failure
9+
EARLYFAIL := PERL6_TEST_DIE_ON_FAIL=0
10+
11+
12+
.PHONY: test bad good
13+
14+
default: test
15+
16+
TESTS := t/*.t
17+
BADTESTS := bad-tests/*.t
18+
GOODTESTS := good-tests/*.t
19+
20+
# the original test suite (i.e., 'make test')
21+
test:
22+
for f in $(TESTS) ; do \
23+
$(DEBUG) $(EARLYFAIL) PERL6LIB=$(LIBPATH) prove -v --exec=$(PERL6) $$f ; \
24+
done
25+
26+
bad:
27+
for f in $(BADTESTS) ; do \
28+
$(DEBUG) $(EARLYFAIL) PERL6LIB=$(LIBPATH) prove -v --exec=$(PERL6) $$f ; \
29+
done
30+
31+
good:
32+
for f in $(GOODTESTS) ; do \
33+
$(DEBUG) $(TA) $(EARLYFAIL) PERL6LIB=$(LIBPATH) prove -v --exec=$(PERL6) $$f ; \
34+
done

TODO

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=================================
2+
REQUIREMENTS FOR A FUTURE RELEASE
3+
=================================
4+
5+
add capability to handle CIDR notation

docs/DEFAULT-SUBS.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# title: Subroutines Exported by Default
2+
3+
### ip-bintoip
4+
- Purpose : Transform a bit string into an IP address
5+
- Params : bit string, IP version
6+
- Returns : IP address on success, undef otherwise
7+
```perl6
8+
sub ip-bintoip(Str:D $binip is copy where &binary,
9+
UInt $ip-version where &ip-version)
10+
returns Str is export {#...}
11+
```
12+
13+
### ip-compress-address
14+
- Purpose : Compress an IPv6 address
15+
- Params : IP, IP version
16+
- Returns : Compressed IP or undef (problem)
17+
```perl6
18+
sub ip-compress-address(Str:D $ip is copy, UInt $ip-version where &ip-version)
19+
returns Str is export {#...}
20+
```
21+
22+
### ip-expand-address
23+
- Purpose : Expand an address from compact notation
24+
- Params : IP address, IP version
25+
- Returns : expanded IP address or undef on failure
26+
```perl6
27+
sub ip-expand-address(Str:D $ip is copy, UInt $ip-version where &ip-version)
28+
returns Str is export {#...}
29+
```
30+
31+
### ip-get-version
32+
- Purpose : Get an IP version
33+
- Params : IP address
34+
- Returns : 4, 6, 0 (don't know)
35+
```perl6
36+
sub ip-get-version(Str:D $ip)
37+
returns UInt is export {#...}
38+
```
39+
40+
### ip-iplengths
41+
- Purpose : Get the length in bits of an IP from its version
42+
- Params : IP version
43+
- Returns : Number of bits: 32, 128, 0 (don't know)
44+
```perl6
45+
sub ip-iplengths(UInt:D $version)
46+
returns UInt is export {#...}
47+
```
48+
49+
### ip-iptobin
50+
- Purpose : Transform an IP address into a bit string
51+
- Params : IP address, IP version
52+
- Returns : bit string on success, undef otherwise
53+
```perl6
54+
sub ip-iptobin(Str:D $ip is copy, UInt $ipversion)
55+
returns Str is export {#...}
56+
```
57+
58+
### ip-is-ipv4
59+
- Purpose : Check if an IP address is version 4
60+
- Params : IP address
61+
- Returns : True (yes) or False (no)
62+
```perl6
63+
sub ip-is-ipv4(Str:D $ip is copy)
64+
returns Bool is export {#...}
65+
```
66+
67+
### ip-is-ipv6
68+
- Purpose : Check if an IP address is version 6
69+
- Params : IP address
70+
- Returns : True (yes) or False (no)
71+
```perl6
72+
sub ip-is-ipv6(Str:D $ip is copy)
73+
returns Bool is export {#...}
74+
```
75+
76+
### ip-remove-leading-zeroes
77+
- Purpose : Remove leading (unneeded) zeroes from octets or quads
78+
- Params : IP address
79+
- Returns : IP address with no unneeded zeroes
80+
```perl6
81+
sub ip-remove-leading-zeroes(Str:D $ip is copy,
82+
UInt $ip-version where &ip-version)
83+
returns Str is export {#...}
84+
```
85+
86+
### ip-reverse-address
87+
- Purpose : Reverse an IP address, use dots for separators for all types
88+
- Params : IP address, IP version
89+
- Returns : Reversed IP address on success, undef otherwise
90+
```perl6
91+
sub ip-reverse-address(Str:D $ip is copy, UInt $ip-version where &ip-version)
92+
returns Str is export {#...}
93+
```
94+
95+
### ip-reverse-domain
96+
- Purpose : Reverse a domain name (only if FQDN, i.e., with dots)
97+
- Params : Domain name
98+
- Returns : Reversed name
99+
```perl6
100+
sub ip-reverse-domain(Str:D $dom is copy)
101+
returns Str is export {#...}
102+
```

0 commit comments

Comments
 (0)