* 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:
parent
5959cc1c32
commit
7bc7916bda
@ -2,7 +2,9 @@ package Qpsmtpd::Address;
|
||||
use strict;
|
||||
|
||||
use overload (
|
||||
'""' => \&format,
|
||||
'""' => \&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;
|
||||
|
Loading…
Reference in New Issue
Block a user