Explorar el Código

Dpkg::Conf: Improve filter function

Use stub functions when the user does not provide them, to allow
filtering with a single grep().
Guillem Jover hace 11 años
padre
commit
5b62b3a0ff
Se han modificado 1 ficheros con 5 adiciones y 8 borrados
  1. 5 8
      scripts/Dpkg/Conf.pm

+ 5 - 8
scripts/Dpkg/Conf.pm

@@ -137,14 +137,11 @@ return true when &$rmfunc($option) or &keepfunc($option) is called.
 
 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}};
-    }
+    my $remove = $opts{remove} // sub { 0 };
+    my $keep = $opts{keep} // sub { 1 };
+
+    @{$self->{options}} = grep { not &$remove($_) and &$keep($_) }
+                               @{$self->{options}};
 }
 
 =item $string = $conf->output($fh)