From 3b09cc25d782100ab4b416bb3ff79738eff3e873 Mon Sep 17 00:00:00 2001 From: John Peacock Date: Tue, 1 Nov 2005 15:14:48 +0000 Subject: [PATCH] * lib/Qpsmtpd/Address.pm Don't overload '<=>' operator casually. Swap host/user portion when comparing (makes it easy to sort by domain). git-svn-id: https://svn.perl.org/qpsmtpd/branches/0.31@558 958fd67b-6ff1-0310-b445-bb7760255be9 --- lib/Qpsmtpd/Address.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Qpsmtpd/Address.pm b/lib/Qpsmtpd/Address.pm index 1d0ea77..56bf689 100644 --- a/lib/Qpsmtpd/Address.pm +++ b/lib/Qpsmtpd/Address.pm @@ -3,8 +3,7 @@ use strict; use overload ( '""' => \&format, - 'cmp' => \&spaceship, - '<=>' => \&spaceship, + 'cmp' => \&addr_cmp, ); sub new { @@ -193,7 +192,7 @@ sub host { return $self->{_host}; } -sub spaceship { +sub addr_cmp { require UNIVERSAL; my ($left, $right, $swap) = @_; my $class = ref($left); @@ -201,12 +200,16 @@ sub spaceship { unless ( UNIVERSAL::isa($right, $class) ) { $right = $class->new($right); } - + + #invert the address so we can sort by domain then user + $left = lc($left->host.'='.$left->user); + $right = lc($right->host.'='.$right->user); + if ( $swap ) { ($right, $left) = ($left, $right); } - return lc($left->format) cmp lc($right->format); + return ($left cmp $right); } 1;