[svn:qpsmtpd] r557 - branches/0.31/lib/Qpsmtpd
[email protected] 31 Oct 2005 17:51:11 -0000
| Newsgroups | perl.cvs.qpsmtpd |
|---|---|
| Message-ID | <[email protected]> |
Author: jpeacock
Date: Mon Oct 31 09:51:11 2005
New Revision: 557
Modified:
branches/0.31/lib/Qpsmtpd/Address.pm
Log:
* 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).
Modified: branches/0.31/lib/Qpsmtpd/Address.pm
==============================================================================
--- branches/0.31/lib/Qpsmtpd/Address.pm (original)
+++ branches/0.31/lib/Qpsmtpd/Address.pm Mon Oct 31 09:51:11 2005
@@ -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;