Skip to content

Commit 4c3c9ea

Browse files
committed
Add processing minus at start of config key to remove from set
1 parent c59a31c commit 4c3c9ea

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

Changes

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Revision history for Perl-Dist-APPerl
2-
v0.0.1 2022-10-10
3-
First packaged version, released on an unsuspecting world.
2+
v0.0.3 2022-10-14
3+
Bumped cosmopolitan versions. Add category to apperlm list. Add
4+
leading '-' support to config parsing to remove items from an
5+
existing set.
46

57
v0.0.2 2022-10-10
68
Add small builds to actions, rewrite acknowledgements.
9+
10+
v0.0.1 2022-10-10
11+
First packaged version, released on an unsuspecting world.

lib/Perl/Dist/APPerl.pm

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package Perl::Dist::APPerl;
22
# Copyright (c) 2022 Gavin Hayes, see LICENSE in the root of the project
3-
use version; our $VERSION = version->declare("v0.0.2");
3+
use version; our $VERSION = version->declare("v0.0.3");
44
use strict;
55
use warnings;
66
use JSON::PP qw(decode_json);
@@ -1218,25 +1218,38 @@ sub _load_apperl_config {
12181218
@configlist = reverse @configlist;
12191219

12201220
# build the config from oldest to newest
1221-
# keys that start with '+' are actually appended to the non-plus variant instead of replacing
1221+
# keys that start with '+' are appended to the non-plus variant instead of replacing
1222+
# keys that start with '-' are removed from the non-plus variant instead of replacing
1223+
# Removing a key added the same stage or vice versa is undefined
12221224
my %itemconfig;
12231225
foreach my $config (@configlist) {
12241226
foreach my $key (keys %$config) {
1225-
if($key =~ /^\+(.+)/) {
1226-
my $realkey = $1;
1227+
if($key =~ /^(\+|\-)(.+)/) {
1228+
my $append = $1 eq '+';
1229+
my $realkey = $2;
12271230
exists $itemconfig{$realkey} or die("cannot append without existing key");
12281231
my $rtype = ref($itemconfig{$realkey});
12291232
$rtype or die("not ref");
1230-
if($rtype eq 'ARRAY') {
1231-
$itemconfig{$realkey} = [@{$itemconfig{$realkey}}, @{$config->{$key}}];
1232-
}
1233-
elsif($rtype eq 'HASH') {
1234-
foreach my $dest (keys %{$config->{$key}}) {
1235-
push @{$itemconfig{$realkey}{$dest}}, @{$config->{$key}{$dest}};
1233+
if($append) {
1234+
if($rtype eq 'ARRAY') {
1235+
$itemconfig{$realkey} = [@{$itemconfig{$realkey}}, @{$config->{$key}}];
1236+
}
1237+
elsif($rtype eq 'HASH') {
1238+
foreach my $dest (keys %{$config->{$key}}) {
1239+
push @{$itemconfig{$realkey}{$dest}}, @{$config->{$key}{$dest}};
1240+
}
1241+
}
1242+
else {
1243+
die($rtype);
12361244
}
12371245
}
12381246
else {
1239-
die($rtype);
1247+
if($rtype eq 'ARRAY') {
1248+
_remove_arr_items_from_arr($itemconfig{$realkey}, $config->{$key});
1249+
}
1250+
else {
1251+
die($rtype);
1252+
}
12401253
}
12411254
}
12421255
else {
@@ -1250,7 +1263,6 @@ sub _load_apperl_config {
12501263
foreach my $path (@{$itemconfig{zip_extra_files}{$destdir}}) {
12511264
$path = abs_path($path);
12521265
$path or die;
1253-
print $path;
12541266
-e $path or die("missing file $path");
12551267
}
12561268
}
@@ -1620,9 +1632,10 @@ Now let's create a very basic C extension.
16201632
' CODE:' \
16211633
' printf("Hello, World!\n");' > MyCExtension/MyCExtension.xs
16221634
1623-
Add it to my_src_build_config in apperl-project.json . Some keys that
1624-
begin with '+' will be merged with the non-plus variant of a base
1625-
config.
1635+
Add it to my_src_build_config in apperl-project.json . Keys that begin
1636+
with '+' will be merged with the non-plus variant of the parent config.
1637+
Keys the begin with '-' will be removed from the non-minus variant of
1638+
the parent config.
16261639
16271640
"perl_repo_files" : { "ext" : [
16281641
"MyCExtension"

0 commit comments

Comments
 (0)