1# ex:ts=8 sw=4:
2# $OpenBSD: PackageRepositoryList.pm,v 1.28 2010/12/24 09:04:14 espie Exp $
3#
4# Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org>
5#
6# Permission to use, copy, modify, and distribute this software for any
7# purpose with or without fee is hereby granted, provided that the above
8# copyright notice and this permission notice appear in all copies.
9#
10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
18use strict;
19use warnings;
20
21package OpenBSD::PackageRepositoryList;
22
23sub new
24{
25	my ($class, $state) = @_;
26	return bless {l => [], k => {}, state => $state}, $class;
27}
28
29sub filter_new
30{
31	my $self = shift;
32	my @l = ();
33	for my $r (@_) {
34		next if $self->{k}{$r};
35		$self->{k}{$r} = 1;
36		push @l, $r;
37	}
38	return @l;
39}
40
41sub add
42{
43	my $self = shift;
44	push @{$self->{l}}, $self->filter_new(@_);
45}
46
47sub prepend
48{
49	my $self = shift;
50	unshift @{$self->{l}}, $self->filter_new(@_);
51}
52
53sub do_something
54{
55	my ($self, $do, $pkgname, @args) = @_;
56	if ($pkgname eq '-') {
57		return OpenBSD::PackageRepository->pipe->new($self->{state})->$do($pkgname, @args);
58	}
59	for my $repo (@{$self->{l}}) {
60		my $r = $repo->$do($pkgname, @args);
61		return $r if defined $r;
62	}
63	return undef;
64}
65
66sub find
67{
68	my ($self, @args) = @_;
69
70	return $self->do_something('find', @args);
71}
72
73sub grabPlist
74{
75	my ($self, @args) = @_;
76	return $self->do_something('grabPlist', @args);
77}
78
79sub match_locations
80{
81	my ($self, @search) = @_;
82	for my $repo (@{$self->{l}}) {
83		my $l = $repo->match_locations(@search);
84		if (@$l > 0) {
85			return $l;
86		}
87	}
88	return [];
89}
90
91sub print_without_src
92{
93	my $self = shift;
94	my @l = ();
95	for my $repo (@$self) {
96		next if $repo->isa("OpenBSD::PackageRepository::Source");
97		push(@l, $repo->url);
98	}
99	return join(':', @l);
100}
101
1021;
103