Selaa lähdekoodia

Dpkg::Conf: add new filter method

This method can be used to select a subset of options either
by exclusion or by inclusion.
Raphaël Hertzog 16 vuotta sitten
vanhempi
commit
9278ba1352
1 muutettua tiedostoa jossa 22 lisäystä ja 1 poistoa
  1. 22 1
      scripts/Dpkg/Conf.pm

+ 22 - 1
scripts/Dpkg/Conf.pm

@@ -18,7 +18,7 @@ package Dpkg::Conf;
 use strict;
 use warnings;
 
-our $VERSION = "1.00";
+our $VERSION = "1.01";
 
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
@@ -122,6 +122,27 @@ sub parse {
     return $count;
 }
 
+=item $conf->filter(remove => $rmfunc)
+
+=item $conf->filter(keep => $keepfunc)
+
+Filter the list of options, either removing or keeping all those that
+return true when &$rmfunc($option) or &keepfunc($option) is called.
+
+=cut
+
+sub filter {
+    my ($self, %opts) = @_;
+    if (defined($opts{'remove'})) {
+	@{$self->{'options'}} = grep { not &{$opts{'remove'}}($_) }
+				     @{$self->{'options'}};
+    }
+    if (defined($opts{'keep'})) {
+	@{$self->{'options'}} = grep { &{$opts{'keep'}}($_) }
+				     @{$self->{'options'}};
+    }
+}
+
 =item $string = $conf->output($fh)
 
 Write the options in the given filehandle (if defined) and return a string