summaryrefslogtreecommitdiffabout
path: root/lib/SlackBuild/Request.pm
Side-by-side diff
Diffstat (limited to 'lib/SlackBuild/Request.pm') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/SlackBuild/Request.pm108
1 files changed, 94 insertions, 14 deletions
diff --git a/lib/SlackBuild/Request.pm b/lib/SlackBuild/Request.pm
index 6b8e132..4ae81d3 100644
--- a/lib/SlackBuild/Request.pm
+++ b/lib/SlackBuild/Request.pm
@@ -7,6 +7,7 @@ use Text::ParseWords;
use JSON;
use File::Basename;
use Safe;
+use feature 'state';
=head1 NAME
@@ -199,15 +200,6 @@ my %generics = (
}
);
-sub _readfile {
- my ($self,$file) = @_;
- local $/ = undef;
- open(my $fd, $file) or croak "can't open file $file: $!";
- my $string = <$fd>;
- close $fd;
- decode_json($string);
-}
-
sub strategy {
my ($self, $attr) = @_;
if ($attr) {
@@ -240,22 +232,25 @@ Build the request from the supplied attribute/value pairs. Allowed attributes
are discussed in detail in the B<ATTRIBUTES> section. Empty argument list
is OK.
- new SlackBuild::Request($file)
+ new SlackBuild::Request($URL)
-Read the request from the disk file B<$file>. The file must contain a single
-request formatted as JSON. No empty lines or comments are allowed.
+Loads request from the $URL. This is equivalent to
+ load SlackBuild::Request($URL)
+
+See the description of B<load>, below.
+
=cut
sub new {
- my $self = bless {}, shift;
+ my $class = shift;
my %a;
if (@_ == 1) {
my $file = shift;
if (ref($file) eq 'HASH') {
%a = %$file;
} else {
- %a = %{$self->_readfile($file)}
+ %a = return $class->load($file);
}
} elsif (@_ % 2) {
croak "bad number of arguments";
@@ -263,12 +258,97 @@ sub new {
%a = @_;
}
+ my $self = bless {}, $class;
while (my ($k,$v) = each %a) {
$self->${\ "set_$k"}($v);
}
return $self;
}
+=head2 load
+
+ $req = load SlackBuild::Request($URL)
+
+Loads request from the supplied $URL. Allowed arguments are:
+
+=over 4
+
+=item Local file name
+
+If $URL is the name of an existing local file, the file is loaded to the
+memory and parsed as JSON object (if it begins with a curly brace), or as
+YAML document.
+
+=item Local directory name
+
+If $URL is the name of an existing local directory, it is searched for
+any files matching the shell globbing pattern C<*.SlackBuild>. If any
+such file is found, its base name is taken as the name of the package,
+and the full pathname of the directory itself as the B<slackbuild_uri>.
+
+=item URL of the remote tarball
+
+If $URL begins with any of C<http://>, C<https://>, C<ftp://>, C<ftps://>,
+and its path name component ends in C<.tar> with optional compression
+suffix (C<.gz>, C<.xz>, C<.lz>, or C<.bz2>), the file name part of the
+URL is taken as the package name and the $URL itself as B<slackbuild_uri>.
+
+=item SBo URL
+
+ sbo:///COMMIT/CATEGORY/PACKAGE
+
+This URL refers the definition of C<PACKAGE> in B<slackbuild.org> repository.
+For example:
+
+ sbo://HEAD/system/cronie
+
+=item Package name
+
+Unqualified package name is looked up in the B<slackbuild.org> repository.
+If it is found, the retrieved data are used to build the request.
+
+=back
+
+=cut
+
+sub load {
+ my ($class, $reqname) = @_;
+
+ my $ldpack = __PACKAGE__ . '::Loader';
+ my @comp = split /::/, $ldpack;
+
+ # Current (as of perl 5.28.0) implementation of "state" only permits
+ # the initialization of scalar variables in scalar context. Therefore
+ # this variable is an array ref.
+ state $loaders //=
+ [map { $_->[1] }
+ sort { $a->[0] <=> $b->[0] }
+ map {
+ my ($modname) = $ldpack . '::' . fileparse($_, '.pm');
+ eval {
+ no strict 'refs';
+ if (scalar %{ $modname.'::' }) {
+ die "INCLUDED $modname";
+ };
+ require $_;
+ my $prio = ${$modname.'::PRIORITY'};
+ die unless $prio && $modname->can('Load');
+ [ $prio, $modname ]
+ }
+ }
+ map { glob File::Spec->catfile($_, '*.pm') }
+ grep { -d $_ }
+ map { File::Spec->catfile($_, @comp) } @INC];
+
+ foreach my $ld (@$loaders) {
+ if (my $req = $ld->Load($reqname)) {
+ return $class->new($req);
+ }
+ }
+
+ croak "unrecognized request type";
+}
+
=head1 STRING REPRESENTATION
When used is string context, objects of this class are represented as

Return to:

Send suggestions and report system problems to the System administrator.