* 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
This commit is contained in:
parent
7bc7916bda
commit
3b09cc25d7
@ -3,8 +3,7 @@ use strict;
|
|||||||
|
|
||||||
use overload (
|
use overload (
|
||||||
'""' => \&format,
|
'""' => \&format,
|
||||||
'cmp' => \&spaceship,
|
'cmp' => \&addr_cmp,
|
||||||
'<=>' => \&spaceship,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
@ -193,7 +192,7 @@ sub host {
|
|||||||
return $self->{_host};
|
return $self->{_host};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub spaceship {
|
sub addr_cmp {
|
||||||
require UNIVERSAL;
|
require UNIVERSAL;
|
||||||
my ($left, $right, $swap) = @_;
|
my ($left, $right, $swap) = @_;
|
||||||
my $class = ref($left);
|
my $class = ref($left);
|
||||||
@ -202,11 +201,15 @@ sub spaceship {
|
|||||||
$right = $class->new($right);
|
$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 ) {
|
if ( $swap ) {
|
||||||
($right, $left) = ($left, $right);
|
($right, $left) = ($left, $right);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lc($left->format) cmp lc($right->format);
|
return ($left cmp $right);
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user