develooper Front page | perl.module-authors | Postings from August 2017

Stringification in Net::IPAddress::Util

Thread Next
Paul Bennett
August 17, 2017 16:56
Stringification in Net::IPAddress::Util
Message ID:
Hi, All,

Quick sanity check, if you please.

Before I start to trying to merge my perl5 Net::IPAddress::Util into
bradclawsie's perl6 IP::Parse, I want to make sure I'm not being crazy
with the way stringification and cmp are overloaded.

IP Addresses exist "on the wire" and naturally sort as 128-bit
Network-Order numbers.

IP Addresses are naturally read & written by humans as strings.

To accommodate both these things, Net::IPAddress::Util overloads '""'
as stringification and <=> as N128-ification (well, actually the
technobabble is deeper, but that's what it amounts to).

The tricky bit is the overloading of the cmp operator.

Since perl5 (and IIRC perl6) uses cmp by default in the sort code
block, my assumption has always been "if people are sorting IP
Addresses they want to sort 'naturally' according to the sensible
semantics", so cmp has been overloaded to do the same thing as <=>.

Is this indeed DWIM, or is it insane troll logic?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About