diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2007-05-14 11:02:16 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2007-05-14 11:02:16 +0000 |
commit | 720febe1bcd1646d4cd6850bd15b98c0df0a1324 (patch) | |
tree | ed68b21b01ec100e1c5bfad9683892533b68a9ca /usr.sbin/pkg_add/OpenBSD/Search.pm | |
parent | 1f94b8d9a850dbb366ebbd30c37f8e1446017987 (diff) |
put Search objects into their own file, finally
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD/Search.pm')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Search.pm | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Search.pm b/usr.sbin/pkg_add/OpenBSD/Search.pm new file mode 100644 index 00000000000..bfc336d9af0 --- /dev/null +++ b/usr.sbin/pkg_add/OpenBSD/Search.pm @@ -0,0 +1,88 @@ +# ex:ts=8 sw=4: +# $OpenBSD: Search.pm,v 1.1 2007/05/14 11:02:15 espie Exp $ +# +# Copyright (c) 2007 Marc Espie <espie@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +package OpenBSD::Search; + +package OpenBSD::Search::PkgSpec; +our @ISA=(qw(OpenBSD::Search)); + +sub match_ref +{ + my ($self, $r) = @_; + my @l = (); + + for my $subpattern (@{$self->{patterns}}) { + require OpenBSD::PkgSpec; + push(@l, OpenBSD::PkgSpec::subpattern_match($subpattern, $r)); + } + return @l; +} + +sub match +{ + my ($self, $o) = @_; + return $self->match_ref($o->list); +} + +sub match_list +{ + my ($self, @list) = @_; + return $self->match_ref(\@list); +} + +sub new +{ + my ($class, $pattern) = @_; + my @l = split /\|/, $pattern; + bless { patterns => \@l }, $class; +} + +package OpenBSD::Search::Stem; +our @ISA=(qw(OpenBSD::Search)); + +sub new +{ + my ($class, $stem) = @_; + + return bless {stem => $stem}, $class; +} + +sub split +{ + my ($class, $pkgname) = @_; + require OpenBSD::PackageName; + + return $class->new(OpenBSD::PackageName::splitstem($pkgname)); +} + +sub match +{ + my ($self, $o) = @_; + return $o->stemlist->find($self->{stem}); +} + +package OpenBSD::Search::PartialStem; +our @ISA=(qw(OpenBSD::Search::Stem)); + +sub match +{ + my ($self, $o) = @_; + return $o->stemlist->find_partial($self->{stem}); +} + + +1; |