summaryrefslogtreecommitdiff
path: root/lib/SlackBuild/Info.pm
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2018-06-15 19:32:36 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2018-06-15 19:32:36 +0200
commit00e5b428ef80f2898142a5e1bbc71cf10142545e (patch)
tree6cef1850b62c6ef8918332918c6eb382037380ea /lib/SlackBuild/Info.pm
parent7c785ca236c25c0f18448c9c01bdb784cbcbf615 (diff)
downloadslackbuilder-00e5b428ef80f2898142a5e1bbc71cf10142545e.tar.gz
slackbuilder-00e5b428ef80f2898142a5e1bbc71cf10142545e.tar.bz2
Introduce strategies for merging Slackware info files into build requests
Three strategies are defined: 1. keep - request attribute takes precedence over the info one 2. overwrite - info attribute takes precedence ovet the request one 3. merge - both atributes are merged (only for HASH and ARRAY attributes). Strategies can be defined using the "strategy" request keyword. Default strategy is "keep" for all attributes, excepting "prereq", for which the default is "merge". * lib/SlackBuild/Info.pm (new): Ignore trailing whitespace. Don't return silently on syntax errors. (str): Rename to as_string. Make sure keys are in lexical order. * lib/SlackBuild/Request.pm: Major rewrite. Introduce new attribute "strategy" - a hash defining merging strategy for request attributes. (str): Rename to as_string. Make sure keys are in lexical order. * t/info.t: Update. * t/request.t: Update.
Diffstat (limited to 'lib/SlackBuild/Info.pm')
-rw-r--r--lib/SlackBuild/Info.pm12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/SlackBuild/Info.pm b/lib/SlackBuild/Info.pm
index 28daf73..4f1c1f1 100644
--- a/lib/SlackBuild/Info.pm
+++ b/lib/SlackBuild/Info.pm
@@ -64,6 +64,7 @@ sub new {
}
while (<$fd>) {
chomp;
+ s/\s+$//;
if (/\\$/) {
chop;
$_ .= <$fd>;
@@ -71,7 +72,8 @@ sub new {
}
s/^\s+//;
next if /^(#.*)?$/;
- return unless /^(?<kw>[A-Za-z_][A-Za-z_0-9]*)="(?<val>.*)"$/;
+ croak "bad input line: $_"
+ unless /^(?<kw>[A-Za-z_][A-Za-z_0-9]*)="(?<val>.*)"$/;
if (exists($attributes{$+{kw}})) {
$self->${\$+{kw}}($+{val});
} else {
@@ -123,15 +125,15 @@ representation is returned by the B<str> method.
=cut
-sub str {
+sub as_string {
my $self = shift;
my %h;
- my @k = sort keys %attributes;
+ my @k = keys %attributes;
@h{@k} = map { $self->${\$_} } @k;
- encode_json(\%h);
+ JSON->new->canonical(1)->encode(\%h);
}
-use overload '""' => sub { shift->str };
+use overload '""' => sub { shift->as_string };
{
no strict 'refs';

Return to:

Send suggestions and report system problems to the System administrator.