sub _cmp {
my ($a1, $a2, $r) = @_;
- my $s1 = $a1->qualified_name;
- my $v1 = $a1->version;
- $s1 .= "-$v1" if defined $v1;
+ if (defined $a2) {
+ my $p1 = $a1->qualified_name;
- 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;
+ unless (Scalar::Util::blessed($a2) && $a2->isa(__PACKAGE__)) {
+ $a2 = eval { __PACKAGE__->new(atom => $a2) };
+ Carp::confess("Can't compare an atom against something that's not an atom or an atom string ($@)") if $@;
+ }
+ my $p2 = $a2->qualified_name;
+
+ if (my $c = $p1 cmp $p2) {
+ return $r ? -$c : $c;
+ }
}
- $s1 cmp $s2;
+ $a1 <=> $a2;
}
sub _stringify {
use strict;
use warnings;
-use Test::More tests => 2 * 5 * ((8 * 7) / 2);
+use Test::More tests => 2 * 8 * ((8 * 7) / 2);
use CPANPLUS::Dist::Gentoo::Atom;
my $bs = "$b";
compare_ok($a, '<=>', $bs, $exp);
- if (my $bv = $b->version) {
+ my $bv = $b->version;
+ if (defined $bv) {
compare_ok($a, '<=>', $bv, $exp);
compare_ok($a, '<=>', "$bv", $exp);
} else {
}
compare_ok($a, 'cmp', $b, $exp);
+
+ my $bz = $b->qualified_name;
+ $bz .= "-$bv" if defined $bv;
+ compare_ok($a, 'cmp', $bz, $exp);
+
+ $bz = "test/zzz";
+ $bz .= "-$bv" if defined $bv;
+ compare_ok($a, 'cmp', $bz, -1);
+ compare_ok($bz, 'cmp', $b, 1);
}
}