refactor parse_pending_delete to sane implemenation

this was quite the mess, a perl greedy match over non-whitespace
character is equivalent to a split on whitespace on, but the latter
is much easier to grasp when looking at this the first time.

Do a real for loop with real variable names and less nest everything
into one line.

the test added in the previous commit should give use the safety net
for that cleanup.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2019-10-18 16:43:25 +02:00
parent fe82406191
commit 7b9d1adeb2

View File

@ -72,10 +72,22 @@ sub write_config {
sub parse_pending_delete {
my ($class, $data) = @_;
$data ||= '';
return {} if !$data;
$data =~ s/[,;]/ /g;
$data =~ s/^\s+//;
return { map { /^(!?)(.*)$/ && ($2, { 'force' => $1 eq '!' ? 1 : 0 } ) } ($data =~ /\S+/g) };
my $pending_deletions = {};
for my $entry (split(/\s+/, $data)) {
my ($force, $key) = $entry =~ /^(!?)(.*)$/;
$pending_deletions->{$key} = {
force => $force ? 1 : 0,
};
}
return $pending_deletions;
}
sub print_pending_delete {