xref: /openbsd/usr.sbin/pkg_add/OpenBSD/Search.pod (revision 6e49571c)
1*6e49571cSdaniel$OpenBSD: Search.pod,v 1.1 2020/12/20 15:30:58 daniel Exp $
2*6e49571cSdaniel
3*6e49571cSdaniel=head1 NAME
4*6e49571cSdaniel
5*6e49571cSdanielOpenBSD::Search - package names matching framework
6*6e49571cSdaniel
7*6e49571cSdaniel=head1 SYNOPSIS
8*6e49571cSdaniel
9*6e49571cSdaniel   use OpenBSD::Search;
10*6e49571cSdaniel
11*6e49571cSdaniel   # pkgspec objects
12*6e49571cSdaniel   my $search_object = OpenBSD::Search::PkgSpec->new($pattern);
13*6e49571cSdaniel   my $filter_object = OpenBSD::Search::Filter->keep_most_recent;
14*6e49571cSdaniel
15*6e49571cSdaniel   # need repository to apply to
16*6e49571cSdaniel
17*6e49571cSdaniel   use OpenBSD::PackageRepository::Installed;
18*6e49571cSdaniel
19*6e49571cSdaniel   my $inst = OpenBSD::PackageRepository::Installed->new;
20*6e49571cSdaniel
21*6e49571cSdaniel   my $list_ref = $inst->match_locations($search_object, $filter_object);
22*6e49571cSdaniel
23*6e49571cSdaniel
24*6e49571cSdaniel=head1 DESCRIPTION
25*6e49571cSdaniel
26*6e49571cSdanielC<OpenBSD::Search> provides a search infrastructure
27*6e49571cSdanielfor C<OpenBSD::PackageRepository> objects.
28*6e49571cSdaniel
29*6e49571cSdanielA given repository can be searched for existing packages using
30*6e49571cSdanielC<$repo-E<gt>match_locations($search1, $filter1, ...);>
31*6e49571cSdaniel
32*6e49571cSdanielIt returns a reference to a list of matching C<OpenBSD::PackageLocation>
33*6e49571cSdanielobjects.
34*6e49571cSdaniel
35*6e49571cSdanielA repository list can be searched in a similar way: the search
36*6e49571cSdanielproceeds through each repository in the list, and stops as soon
37*6e49571cSdanielas it finds a non-empty match (similar to C<ld -L> rules).
38*6e49571cSdaniel
39*6e49571cSdanielThe first search object C<$search> is used to find the basic set
40*6e49571cSdanielof matching packages, and further objects are used to weed out
41*6e49571cSdanielunwanted elements from the list.
42*6e49571cSdaniel
43*6e49571cSdanielComplex searches must be built as lists of filter objects, in
44*6e49571cSdanielorder to preserve RepositoryList semantics, and ensure the correct
45*6e49571cSdanielnon-empty first match is returned.
46*6e49571cSdaniel
47*6e49571cSdanielThe infrastructure provides the following objects:
48*6e49571cSdaniel
49*6e49571cSdaniel=over 4
50*6e49571cSdaniel
51*6e49571cSdaniel=item OpenBSD::Search::PkgSpec
52*6e49571cSdaniel
53*6e49571cSdanielC<OpenBSD::PkgSpec> filters.
54*6e49571cSdaniel
55*6e49571cSdaniel=item OpenBSD::Search::Stem
56*6e49571cSdaniel
57*6e49571cSdanielfinds all packages with a given stem.
58*6e49571cSdaniel
59*6e49571cSdaniel=item OpenBSD::Search::PartialStem
60*6e49571cSdaniel
61*6e49571cSdanielfinds all packages including a partial stem.
62*6e49571cSdaniel
63*6e49571cSdaniel=item OpenBSD::Search::Filter
64*6e49571cSdaniel
65*6e49571cSdanielfilters package list through further tests.
66*6e49571cSdaniel
67*6e49571cSdaniel=back
68