* 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
@ -3,6 +3,8 @@ use strict;
|
|||||||
|
|
||||||
use overload (
|
use overload (
|
||||||
'""' => \&format,
|
'""' => \&format,
|
||||||
|
'cmp' => \&spaceship,
|
||||||
|
'<=>' => \&spaceship,
|
||||||
);
|
);
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
@ -191,4 +193,20 @@ sub host {
|
|||||||
return $self->{_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;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user