From: Vincent Pit Date: Sun, 29 Nov 2009 00:28:56 +0000 (+0100) Subject: Add string comparison for atoms X-Git-Tag: v0.09~11 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=e8b4c54d60a1bab156b8bc270df2d95327ddd4e1;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git Add string comparison for atoms --- diff --git a/lib/CPANPLUS/Dist/Gentoo/Atom.pm b/lib/CPANPLUS/Dist/Gentoo/Atom.pm index 8ee0f88..002b349 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Atom.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Atom.pm @@ -10,6 +10,7 @@ use Scalar::Util (); use overload ( '<=>' => \&_spaceship, + 'cmp' => \&_cmp, '""' => \&_stringify, ); @@ -96,6 +97,25 @@ sub _spaceship { return $v1 <=> $v2; } +sub _cmp { + my ($a1, $a2, $r) = @_; + + my $s1 = $a1->qualified_name; + my $v1 = $a1->version; + $s1 .= "-$v1" if defined $v1; + + my $s2; + if (Scalar::Util::blessed($a2) and $a2->isa(__PACKAGE__)) { + $s2 = $a2->qualified_name; + my $v2 = $a2->version; + $s2 .= "-$v2" if defined $v2; + } else { + $s2 = $a2; + } + + $s1 cmp $s2; +} + sub _stringify { my ($a) = @_;