From 7bc7916bda3750fbf3e6c82bd522c87cc4801010 Mon Sep 17 00:00:00 2001 From: John Peacock Date: Mon, 31 Oct 2005 17:51:11 +0000 Subject: [PATCH] * 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 --- lib/Qpsmtpd/Address.pm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Qpsmtpd/Address.pm b/lib/Qpsmtpd/Address.pm index a2fad98..1d0ea77 100644 --- a/lib/Qpsmtpd/Address.pm +++ b/lib/Qpsmtpd/Address.pm @@ -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;