summaryrefslogtreecommitdiff
path: root/lib/SlackBuild/Info.pm
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2018-01-24 16:07:34 +0100
committerSergey Poznyakoff <gray@gnu.org.ua>2018-01-24 16:07:34 +0100
commit17b5bf548a58233f4f106ad88c9b191722cc33a3 (patch)
treeb7fdab108122f4efa3ec28ee592d30c638ce26f1 /lib/SlackBuild/Info.pm
parentb46d32e586a2d798eaf87b6b7304986b5c782dfb (diff)
downloadslackbuilder-17b5bf548a58233f4f106ad88c9b191722cc33a3.tar.gz
slackbuilder-17b5bf548a58233f4f106ad88c9b191722cc33a3.tar.bz2
Use info file, if available, to fill in the missing fields in the request.
It is now possible to pass a ULR of the slackbuilds.org file in order to build the package. * lib/SlackBuild/Info.pm: New file. * lib/SlackBuild/Request.pm: New file. * t/info.t: New testcase. * t/request.t: New testcase. * lib/SlackBuild/Archive.pm: Use SlackBuild::Info instead of directly parsing the info file. * lib/SlackBuilder.pm: Use SlackBuild::Request. In particular, this means that information missing from the request is filled by the data from the info file, if available. * slackbuilder: If the filename is not found on disk, see if the argument looks like a remote slackbuild URL. If so, create a minimal request and use it in the hope that missing info will be obtained from the info file after download.
Diffstat (limited to 'lib/SlackBuild/Info.pm')
-rw-r--r--lib/SlackBuild/Info.pm122
1 files changed, 122 insertions, 0 deletions
diff --git a/lib/SlackBuild/Info.pm b/lib/SlackBuild/Info.pm
new file mode 100644
index 0000000..251e9e4
--- /dev/null
+++ b/lib/SlackBuild/Info.pm
@@ -0,0 +1,122 @@
+package SlackBuild::Info;
+use strict;
+use warnings;
+use Carp;
+use Text::ParseWords;
+use JSON;
+
+=head1 NAME
+
+SlackBuild::Info - a slackbuilds.org info object
+
+=head1 DESCRIPTION
+
+A representation of the B<slackbuilds.org> "info" file. See
+the L<https://slackbuilds.org/guidelines/>, section B<$PRGNAM.info file>.
+
+=cut
+
+my %attributes = (
+ PRGNAM => 1,
+ VERSION => 1,
+ HOMEPAGE => 1,
+ DOWNLOAD => 'ARRAY',
+ MD5SUM => 'ARRAY',
+ DOWNLOAD_x86_64 => 'ARRAY',
+ MD5SUM_x86_64 => 'ARRAY',
+ REQUIRES => 'ARRAY',
+ MAINTAINER => 1,
+ EMAIL => 1
+);
+
+=head1 CONSTRUCTOR
+
+ new SlackBuild::Info(FH)
+
+Reads the attributes from the file handle B<FH>.
+
+ new SlackBuild::Info(\$string)
+
+Reads the attributes from the string B<$string>, which must contain the text
+of an info file.
+
+ new SlackBuild::Info($filename)
+
+Reads the attributes from the file named B<$filename>.
+
+ new SlackBuild::Info(ATTR => VALUE, ...)
+
+Directly initializes attributes with the given values
+
+ new SlackBuild::Info
+
+Returns an empty info object.
+
+=cut
+
+sub new {
+ my $class = shift;
+ my $self = bless {}, $class;
+ if (my $arg = shift) {
+ my $fd;
+ if (ref($arg) eq 'GLOB') {
+ open($fd, '<&', $arg)
+ or croak "can't dup filehandle: $!";
+ } else {
+ open($fd, '<', $arg)
+ or croak "can't open $arg: $!";
+ }
+ while (<$fd>) {
+ chomp;
+ s/^\s+//;
+ next if /^(#.*)?$/;
+ return unless /^(?<kw>[A-Za-z_][A-Za-z_0-9]*)="(?<val>.*)"$/;
+ if (exists($attributes{$+{kw}})) {
+ $self->${\$+{kw}}($+{val});
+ } else {
+ carp "ignoring unrecognized line: $_";
+ }
+ }
+ close $fd;
+ }
+ return $self;
+}
+
+=head1 STRING REPRESENTATION
+
+When used is string context, objects of this class are represented as
+JSON objects with attribute names sorted in lexical order. The same
+representation is returned by the B<str> method.
+
+=cut
+
+sub str {
+ my $self = shift;
+ my %h;
+ my @k = sort keys %attributes;
+ @h{@k} = map { $self->${\$_} } @k;
+ encode_json(\%h);
+}
+
+use overload '""' => sub { shift->str };
+
+{
+ no strict 'refs';
+ use feature 'state';
+ while (my ($attr,$type) = each %attributes) {
+ *{ __PACKAGE__ . '::' . $attr } = sub {
+ my $self = shift;
+ croak "too many arguments" if @_ > 1;
+ if (my $v = shift) {
+ if ($type eq 'ARRAY') {
+ $self->{$attr} = [parse_line('\s+', 0, $v)];
+ } else {
+ $self->{$attr} = $v;
+ }
+ }
+ return $self->{$attr};
+ }
+ }
+}
+
+1;

Return to:

Send suggestions and report system problems to the System administrator.