+=head1 PRIVATE FUNCTIONS
+
+=head2 __handle_pkg_src_and_maint
+
+ my @packages = __handle_pkg_src_and_maint(map {exists $param{$_}?($_,$param{$_}):()}
+ qw(package src maint)
+ );
+
+Turn package/src/maint into a list of packages
+
+=cut
+
+sub __handle_pkg_src_and_maint{
+ my %param = validate_with(params => \@_,
+ spec => {package => {type => SCALAR|ARRAYREF,
+ optional => 1,
+ },
+ src => {type => SCALAR|ARRAYREF,
+ optional => 1,
+ },
+ maint => {type => SCALAR|ARRAYREF,
+ optional => 1,
+ },
+ },
+ allow_extra => 1,
+ );
+
+ my @packages;
+ @packages = make_list($param{package}) if exists $param{package};
+ my $package_keys = @packages?1:0;
+ my %packages;
+ @packages{@packages} = (1) x @packages;
+ if (exists $param{src}) {
+ # We only want to increment the number of keys if there is
+ # something to match
+ my $key_inc = 0;
+ # in case there are binaries with the same name as the
+ # source
+ my %_temp_p = ();
+ for my $package ((map {getsrcpkgs($_)} make_list($param{src}))) {
+ $packages{$package}++ unless exists $_temp_p{$package};
+ $_temp_p{$package} = 1;
+ $key_inc=1;
+ }
+ for my $package (make_list($param{src})) {
+ $packages{"src:$package"}++ unless exists $_temp_p{"src:$package"};
+ $_temp_p{"src:$package"} = 1;
+ $key_inc=1;
+ # As a temporary hack, we will also include $param{src}
+ # in this list for packages passed which do not have a
+ # corresponding binary package
+ if (not exists getpkgsrc()->{$package}) {
+ $packages{$package}++ unless exists $_temp_p{$package};
+ $_temp_p{$package} = 1;
+ }
+ }
+ $package_keys += $key_inc;
+ }
+ if (exists $param{maint}) {
+ my $key_inc = 0;
+ my %_temp_p = ();
+ for my $package (package_maintainer(maintainer=>$param{maint})) {
+ $packages{$package}++ unless exists $_temp_p{$package};
+ $_temp_p{$package} = 1;
+ $key_inc = 1;
+ }
+ $package_keys += $key_inc;
+ }
+ return grep {$packages{$_} >= $package_keys} keys %packages;
+}
+
+my %field_match = (
+ 'subject' => \&__contains_field_match,
+ 'tags' => sub {
+ my ($field, $values, $status) = @_;
+ my %values = map {$_=>1} @$values;
+ foreach my $t (split /\s+/, $status->{$field}) {
+ return 1 if (defined $values{$t});
+ }
+ return 0;
+ },
+ 'severity' => \&__exact_field_match,
+ 'pending' => \&__exact_field_match,
+ 'package' => \&__exact_field_match,
+ 'originator' => \&__contains_field_match,
+ 'forwarded' => \&__contains_field_match,
+ 'owner' => \&__contains_field_match,
+);
+
+sub __bug_matches {
+ my ($hash, $status) = @_;
+ foreach my $key( keys( %$hash ) ) {
+ my $value = $hash->{$key};
+ next unless exists $field_match{$key};
+ my $sub = $field_match{$key};
+ if (not defined $sub) {
+ die "No defined subroutine for key: $key";
+ }
+ return 1 if ($sub->($key, $value, $status));
+ }
+ return 0;
+}
+
+sub __exact_field_match {
+ my ($field, $values, $status) = @_;
+ my @values = @$values;
+ my @ret = grep {$_ eq $status->{$field} } @values;
+ $#ret != -1;
+}