diff --git a/Changes b/Changes index 8528cf4..45576d9 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension NetAddr::IP +4.071 Mon Sep 30 13:41:03 PDT 2013 + add method "canon" by request from + 4.070 Thu Sep 12 12:54:22 PDT 2013 nth documention error fixed. thanks to Anton tobez@tobez.org diff --git a/IP.pm b/IP.pm index 6ba1863..5d01e1a 100644 --- a/IP.pm +++ b/IP.pm @@ -37,7 +37,7 @@ @ISA = qw(Exporter NetAddr::IP::Lite); -$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.70 $ =~ /\d+/g) }; +$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.71 $ =~ /\d+/g) }; $rfc3021 = 0; @@ -848,6 +848,20 @@ return _compV6($addr); } +=item C<-Ecanon()> + +Returns the address part in canonical notation as a string. For +ipV4, this is dotted quad, and is the same as the return value from +"->addr()". For ipV6 it is as per RFC5952, and is the same as the LOWER CASE value +returned by "->short()". + +=cut + +sub canon($) { + my $addr = $_[0]->addr; + return $_[0]->{isv6} ? lc _compV6($addr) : $addr; +} + =item C<-Efull()> Returns the address part in FULL notation for diff --git a/MANIFEST b/MANIFEST index 2e72d4b..9753d71 100644 --- a/MANIFEST +++ b/MANIFEST @@ -8,6 +8,7 @@ Makefile.PL TODO docs/rfc1884.txt +t/canon.t t/constants.t t/full.t t/full6.t diff --git a/META.yml b/META.yml index f1ec3e3..c2d64ed 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- #YAML:1.0 name: NetAddr-IP -version: 4.070 +version: 4.071 abstract: Manages IPv4 and IPv6 addresses and subnets license: ~ author: diff --git a/t/canon.t b/t/canon.t new file mode 100644 index 0000000..91b72c3 --- /dev/null +++ b/t/canon.t @@ -0,0 +1,23 @@ +use Test::More; + +my %cases = +( + '127.1' => '127.0.0.1', + 'DEAD:BEEF::1' => 'dead:beef::1', + + '1234:5678:90AB:CDEF:0123:4567:890A:BCDE' + => '1234:5678:90ab:cdef:123:4567:890a:bcde', +); + +my $tests = keys %cases; +plan tests => 1 + $tests; + +SKIP: { + use_ok('NetAddr::IP') or skip "Failed to load NetAddr::IP", $tests; + for my $c (sort keys %cases) + { + my $ip = new NetAddr::IP $c; + my $rv = $ip->canon; + is($rv, $cases{$c}, "canon($c ) returns $rv"); + } +}