diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2018-06-19 16:36:58 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2018-06-19 16:52:11 +0200 |
commit | 5091d2c21569478bab5eeac0ad1cf6c4e459ab87 (patch) | |
tree | 850e286ecdbde28bb70f490975eb9a83b2a61ba9 /lib/SlackBuild | |
parent | 7118ffe16d97b2a589047408ea704133a3aa28ad (diff) | |
download | slackbuilder-5091d2c21569478bab5eeac0ad1cf6c4e459ab87.tar.gz slackbuilder-5091d2c21569478bab5eeac0ad1cf6c4e459ab87.tar.bz2 |
Introduce SBo URIs
* lib/Net/SBo.pm: New file. Slackbuilds.org repository access.
* lib/URI/sbo.pm: New file. sbo:// URIs
* lib/LWP/Protocol/sbo.pm: New file. LWP protocol handler for sbo:// URIs
* lib/SlackBuild/Registry/Backend/FS.pm: Scan the directory before
returning from the constructor. The lookup method uses cached data. This
allows to speed-up multiple look-ups.
* slackbuilder: If argument is neither an existing file nor https?
URI, treat it as a slackbuild package name
Diffstat (limited to 'lib/SlackBuild')
-rw-r--r-- | lib/SlackBuild/Registry/Backend/FS.pm | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/lib/SlackBuild/Registry/Backend/FS.pm b/lib/SlackBuild/Registry/Backend/FS.pm index f71e72a..d7d6918 100644 --- a/lib/SlackBuild/Registry/Backend/FS.pm +++ b/lib/SlackBuild/Registry/Backend/FS.pm @@ -16,7 +16,9 @@ SlackBuild::Registry::Backend::FS - filesystem backend for slackbuild registry =head1 SYNOPSIS $reg = new SlackBuild::Registry(dir => DIRECTORY); - my @a = $x->lookup('openssl', version => '1.0.2m'); + $pat = new SlackBuild::Registry::Pattern(package => 'openssl', + version => '1.0.2m'); + @a = $x->lookup($pat); =head1 METHODS @@ -36,33 +38,23 @@ sub new { croak "required parameter dir not present"; } croak "too many arguments" if keys %_; + $self->scan; return $self; } my @architectures = qw(i386 x86_64 arm noarch); my @suffixes = qw(.tgz .txz); -=head2 lookup - - @a = $backend->lookup($pattern) - -Returns a sorted array of SlackBuild::Registry::Record objects matching the -B<SlackBuild::Registry::Pattern> object B<$pattern>. - -=cut - -sub lookup { - my ($self, $pred) = @_; - my $pkg = $pred->package; +sub scan { + my $self = shift; + my $pat = "*-*-*-*"; - my $pat = "$pkg-*-*-*"; - - my $rx = '^' . qr($pkg) . '-' + my $rx = '^(?<pkg>.+)-' . '(?<vpfx>.*?)' . '(?<version>\d+(?:\.\d+)*.*?)' . '-(?<arch>' . regexp_opt(@architectures) . ')' . '-(?<build>\d+)(?<rest>[[:punct:]].*)?$'; - my @result = sort { + $self->{ls} = [sort { my $d; if ($d = ($a->package || '') cmp ($b->package || '')) { $d @@ -75,13 +67,12 @@ sub lookup { ($b->build || 1) <=> ($a->build || 1) } } - grep { $pred->matches($_) } map { my ($name,$path,$suffix) = fileparse($_, @suffixes); if ($name =~ m{$rx}) { my $st = stat($_); if (S_ISREG($st->mode)) { - new SlackBuild::Registry::Record($pkg, + new SlackBuild::Registry::Record($+{pkg}, version => $+{version}, arch => $+{arch}, build => $+{build}, @@ -93,7 +84,42 @@ sub lookup { } else { () } - } (glob File::Spec->catfile($self->{dir}, $pat)); + } (glob File::Spec->catfile($self->{dir}, $pat))]; + + $self->{index}{$self->{ls}[0]->package}[0] = 0; + my $i; + for ($i = 1; $i < @{$self->{ls}}; $i++) { + unless ($self->{ls}[$i]->package eq $self->{ls}[$i-1]->package) { + $self->{index}{$self->{ls}[$i-1]->package}[1] = $i-1; + $self->{index}{$self->{ls}[$i]->package}[0] = $i; + } + } + $self->{index}{$self->{ls}[$i-1]->package}[1] = $i; +} + +=head2 lookup + + @a = $backend->lookup($pattern) + +Returns a sorted array of SlackBuild::Registry::Record objects matching the +B<SlackBuild::Registry::Pattern> object B<$pattern>. + +=cut + +sub lookup { + my ($self, $pred) = @_; + my $pkg = $pred->package; + + my @result; + if ($pkg) { + if (my $idx = $self->{index}{$pkg}) { + @result = grep { $pred->matches($_) } + @{$self->{ls}}[$idx->[0] .. $idx->[1]]; + } + } else { + @result = grep { $pred->matches($_) } @{$self->{ls}}; + } + if (wantarray) { (@result) } else { |