diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2019-03-29 16:15:35 +0100 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2019-03-29 16:15:35 +0100 |
commit | 3ac0a7b9a2b31b98700ee3199db6feda7f08454d (patch) | |
tree | 4fa3e44c32e68be29e7b534943c149ed34c2d3ac /lib/SlackBuild | |
parent | 14099edd51d7d651e315670c1dab493423ed3e2a (diff) | |
download | slackbuilder-3ac0a7b9a2b31b98700ee3199db6feda7f08454d.tar.gz slackbuilder-3ac0a7b9a2b31b98700ee3199db6feda7f08454d.tar.bz2 |
Redo logfile support.
* lib/SlackBuild/Registry/Record.pm (split): New class method.
* lib/SlackBuild/Registry/Backend/FS.pm (scan): Use
SlackBuild::Registry::Record->split.
* t/regrec.t: Test SlackBuild::Registry::Record->split.
* lib/SlackBuild/Request.pm (merge): New method (for future
use).
Introduce default attribute values.
Set default for build to 1.
* lib/SlackBuild/URI.pm (download): Bugfix. Pass one
argument to $result->content_type.
* lib/SlackBuilder.pm: Create log as a temporary file. Rename it to
its final name after the build has finished. This is necessary because
at the initial stage the request might lack some of the parameters needed
to construct the log file name.
Diffstat (limited to 'lib/SlackBuild')
-rw-r--r-- | lib/SlackBuild/Registry/Backend/FS.pm | 23 | ||||
-rw-r--r-- | lib/SlackBuild/Registry/Record.pm | 28 | ||||
-rw-r--r-- | lib/SlackBuild/Request.pm | 15 | ||||
-rw-r--r-- | lib/SlackBuild/URI.pm | 2 |
4 files changed, 48 insertions, 20 deletions
diff --git a/lib/SlackBuild/Registry/Backend/FS.pm b/lib/SlackBuild/Registry/Backend/FS.pm index d7d6918..61cbe7d 100644 --- a/lib/SlackBuild/Registry/Backend/FS.pm +++ b/lib/SlackBuild/Registry/Backend/FS.pm @@ -3,7 +3,6 @@ use strict; use warnings; use Carp; use File::Basename; -use List::Regexp; use File::stat; use File::Spec; use Fcntl ':mode'; @@ -42,18 +41,12 @@ sub new { return $self; } -my @architectures = qw(i386 x86_64 arm noarch); my @suffixes = qw(.tgz .txz); sub scan { my $self = shift; my $pat = "*-*-*-*"; - my $rx = '^(?<pkg>.+)-' - . '(?<vpfx>.*?)' - . '(?<version>\d+(?:\.\d+)*.*?)' - . '-(?<arch>' . regexp_opt(@architectures) . ')' - . '-(?<build>\d+)(?<rest>[[:punct:]].*)?$'; $self->{ls} = [sort { my $d; if ($d = ($a->package || '') cmp ($b->package || '')) { @@ -69,21 +62,17 @@ sub scan { } map { my ($name,$path,$suffix) = fileparse($_, @suffixes); - if ($name =~ m{$rx}) { + my $rec = SlackBuild::Registry::Record->split($name); + if ($rec) { my $st = stat($_); if (S_ISREG($st->mode)) { - new SlackBuild::Registry::Record($+{pkg}, - version => $+{version}, - arch => $+{arch}, - build => $+{build}, - date => $st->mtime, - filename => File::Spec->abs2rel($_, $self->{dir})) + $rec->date($st->mtime); + $rec->filename(File::Spec->abs2rel($_, $self->{dir})); } else { - () + $rec = undef; } - } else { - () } + $rec } (glob File::Spec->catfile($self->{dir}, $pat))]; $self->{index}{$self->{ls}[0]->package}[0] = 0; diff --git a/lib/SlackBuild/Registry/Record.pm b/lib/SlackBuild/Registry/Record.pm index 3af5f96..81a705c 100644 --- a/lib/SlackBuild/Registry/Record.pm +++ b/lib/SlackBuild/Registry/Record.pm @@ -5,6 +5,8 @@ use Carp; use SlackBuild::Base qw(package arch build date filename); use SlackBuild::Registry::Version; use Scalar::Util qw(blessed); +use List::Regexp; +use File::Basename; =head2 new @@ -30,6 +32,32 @@ sub new { return $self; } +my @architectures = qw(i386 x86_64 arm noarch); + +my $rx = '^(?<pkg>.+)-' + . '(?<vpfx>.*?)' + . '(?<version>\d+(?:\.\d+)*.*?)' + . '-(?<arch>' . regexp_opt(@architectures) . ')' + . '-(?<build>\d+)(?<rest>[[:punct:]].*)?$'; + +=head2 split + + $r = SlackBuild::Registry::Record->split($filename, %opt) + +=cut + +sub split { + my ($class, $filename, %opt) = @_; + if (basename($filename) =~ m{$rx}) { + return $class->new($+{pkg}, + version => $+{version}, + arch => $+{arch}, + build => $+{build}, + filename => $filename, + %opt); + } +} + sub version { my $self = shift; if (@_) { diff --git a/lib/SlackBuild/Request.pm b/lib/SlackBuild/Request.pm index 4ae81d3..3876b56 100644 --- a/lib/SlackBuild/Request.pm +++ b/lib/SlackBuild/Request.pm @@ -107,6 +107,7 @@ my %attributes = ( }, build => { type => 'SCALAR', + default => 1, }, slackbuild_uri => { type => 'SCALAR', @@ -163,7 +164,7 @@ my %generics = ( }, set => sub { my ($self, $attr, $value, $strat) = @_; - croak "hashref expected" unless ref($value) eq 'HASH'; + croak "hashref expected when setting $attr" unless ref($value) eq 'HASH'; if (defined($self->{$attr}) && defined($strat) && $strat ne 'keep') { if ($strat eq 'merge') { @@ -349,6 +350,15 @@ sub load { croak "unrecognized request type"; } +sub merge { + my ($self, $other) = @_; + foreach my $attr (keys %attributes) { + unless (defined($self->{$attr})) { + $self->${\ "set_$attr"}($other->${\ $attr}); + } + } +} + =head1 STRING REPRESENTATION When used is string context, objects of this class are represented as @@ -450,7 +460,8 @@ sub set_prereq { unless (__PACKAGE__->can($attr)) { *{ __PACKAGE__ . '::' . $attr } = sub { my $self = shift; - return $self->${ \ $generics{$descr->{type}}{get} }($attr); + return $self->${ \ $generics{$descr->{type}}{get} }($attr) + || $descr->{default}; } } unless (__PACKAGE__->can("set_$attr")) { diff --git a/lib/SlackBuild/URI.pm b/lib/SlackBuild/URI.pm index 91b10c2..b0d6724 100644 --- a/lib/SlackBuild/URI.pm +++ b/lib/SlackBuild/URI.pm @@ -77,7 +77,7 @@ sub download { my $result = new SlackBuild::Download($self, success => $response->is_success); if ($response->is_success) { - $result->content_type($response->content_type); + $result->content_type(scalar($response->content_type)); } else { $self->logger->error("$self: " . $response->status_line); } |