]> git.deb.at Git - deb/packages.git/blobdiff - lib/Deb/Versions.pm
Create index pages
[deb/packages.git] / lib / Deb / Versions.pm
index 4e0d99bc1f18ce009383d5b0beeeced49d8e04af..4f3b3207b0d8130d92706e181daf62884574000a 100644 (file)
@@ -64,9 +64,10 @@ package Deb::Versions;
 
 use strict;
 use Exporter;
+use Carp qw(cluck);
 
 our @ISA = qw( Exporter );
-our @EXPORT = qw( version_cmp version_sort );
+our @EXPORT = qw( version_cmp version_sort suites_cmp suites_sort );
 
 our $VERSION = v1.0.0;
 
@@ -79,7 +80,7 @@ sub version_cmp {
        ( $e1, $u1, $d1 ) = ( $1, $2, $3 );
        $e1 ||= 0;
     } else {
-       warn "This seems not to be a valid version number:"
+       cluck "This seems not to be a valid version number:"
            . "<$ver1>\n";
        return -1;
     }
@@ -87,7 +88,7 @@ sub version_cmp {
         ( $e2, $u2, $d2 ) = ( $1, $2, $3 );
        $e2 ||= 0;
     } else {
-        warn "This seems not to be a valid version number:"
+        cluck "This seems not to be a valid version number:"
             . "<$ver2>\n";
         return 1;
     }
@@ -152,6 +153,46 @@ sub _lcmp {
     return length( $v1 ) <=> length( $v2 );
 }
 
+our @SUITES_SORT = qw( woody oldstable sarge stable stable-proposed-updates
+                      etch testing testing-proposed-updates sid unstable
+                      experimental warty hoary hoary-backports breezy
+                      breezy-backports dapper );
+our @ARCHIVE_SORT = qw( non-US security updates volatile backports );
+our @PRIORITY_SORT = qw( required important standard optional extra );
+my $i = 1000;
+our %suites_sort = map { $_ => ($i-=10) } @SUITES_SORT;
+our %priority_sort = map { $_ => $i-- } @PRIORITY_SORT;
+$i = 0;
+our %archive_sort = map { $_ => $i++ } @ARCHIVE_SORT;
+
+sub suites_cmp {
+    my ($s_a, $s_b) = @_;
+    my $cmp_a = $suites_sort{$s_a};
+    unless ($cmp_a) {
+       $cmp_a = $suites_sort{$1} - $archive_sort{$2}
+       if $s_a =~ m;^(.+?)[/-](.*)$;o;
+    }
+    my $cmp_b = $suites_sort{$s_b};
+    unless ($cmp_b) {
+       $cmp_b = $suites_sort{$1} - $archive_sort{$2}
+       if $s_b =~ m;^(.+?)[/-](.*)$;o;
+    }
+    return ($cmp_a <=> $cmp_b);
+}
+
+sub suites_sort {
+    return sort { suites_cmp( $b, $a ) } @_;
+}
+
+sub priority_cmp {
+    return ($priority_sort{$_[0]} <=> $priority_sort{$_[1]});
+}
+
+sub priority_sort {
+    return sort { priority_cmp( $b, $a ) } @_;
+}
+
+
 1;
 __END__