* lib/Qpsmtpd/Address.pm

Since we are already overloading stringify, we might as well
    overload comparisons as well (this may be too simplistic a test).

git-svn-id: https://svn.perl.org/qpsmtpd/branches/0.31@557 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
John Peacock 2005-10-31 17:51:11 +00:00
parent 5959cc1c32
commit 7bc7916bda

View File

@ -3,6 +3,8 @@ use strict;
use overload (
'""' => \&format,
'cmp' => \&spaceship,
'<=>' => \&spaceship,
);
sub new {
@ -191,4 +193,20 @@ sub host {
return $self->{_host};
}
sub spaceship {
require UNIVERSAL;
my ($left, $right, $swap) = @_;
my $class = ref($left);
unless ( UNIVERSAL::isa($right, $class) ) {
$right = $class->new($right);
}
if ( $swap ) {
($right, $left) = ($left, $right);
}
return lc($left->format) cmp lc($right->format);
}
1;