r28066 - /trunk/dh-make-perl/lib/Debian/Dependencies.pm

dmn at users.alioth.debian.org dmn at users.alioth.debian.org
Thu Dec 11 14:26:51 UTC 2008


Author: dmn
Date: Thu Dec 11 14:26:49 2008
New Revision: 28066

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=28066
Log:
Debian::Dependencies: add prune method

Modified:
    trunk/dh-make-perl/lib/Debian/Dependencies.pm

Modified: trunk/dh-make-perl/lib/Debian/Dependencies.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/dh-make-perl/lib/Debian/Dependencies.pm?rev=28066&op=diff
==============================================================================
--- trunk/dh-make-perl/lib/Debian/Dependencies.pm (original)
+++ trunk/dh-make-perl/lib/Debian/Dependencies.pm Thu Dec 11 14:26:49 2008
@@ -3,6 +3,7 @@
 use strict;
 use warnings;
 
+use AptPkg::Config;
 use Debian::Dependency;
 
 use overload '""'   => \&stringify;
@@ -62,9 +63,14 @@
 
 =over 4
 
-XXX TO BE FILLED
+=item prune()
 
-=back
+Reduces the list of dependencies by removing duplicate or covering ones. The
+resulting list is also sorted by package name.
+
+For example, if you have libppi-perl, libppi-perl (>= 3.0), libarm-perl,
+libalpa-perl, libarm-perl (>= 2), calling C<prune> will leave you with
+libalpa-perl, libarm-perl (>= 2), libppi-perl (>= 3.0)
 
 =cut
 
@@ -73,6 +79,33 @@
 
     return join( ', ', @$self );
 }
+
+sub prune(@) {
+    my $self = shift;
+    my %deps;
+    for (@$self) {
+        my $p = $_->pkg;
+        my $v = $_->ver;
+        if ( exists $deps{$p} ) {
+            my $cur_ver = $deps{$p}->ver;
+
+            $deps{$p} = $v
+                if defined($v) and not defined($cur_ver)
+                    or $AptPkg::Config::_config->system->versioning->compare(
+                        $cur_ver, $v ) < 0;
+        }
+        else {
+            $deps{$p} = $_;
+        }
+
+    }
+
+    @$self = map( $deps{$_}, sort( keys(%deps) ) );
+}
+
+=back
+
+=cut
 
 1;
 




More information about the Pkg-perl-cvs-commits mailing list