From 46bea9790a5556741bff7f535d73c77d7ece5520 Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Sun, 22 Oct 2023 16:33:18 -0500 Subject: [PATCH] Workaround for given-when bug --- minimalist.pl | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/minimalist.pl b/minimalist.pl index d8f355b..92cd3d4 100755 --- a/minimalist.pl +++ b/minimalist.pl @@ -1044,8 +1044,13 @@ my $msg = ''; %conf = %global_conf; + my $verb = shift @cmd; + + # the given() construct will somehow destroy verb + my $saved_verb = $verb; + #TODO: reset config to global config after each iteration. - given (shift @cmd) { + given ($verb) { when ([qw/stop exit end thanks --/]) { last } when ('help') { $msg .= "\n".mt('_USAGE') } @@ -1187,7 +1192,9 @@ break; } - when ('who') { + # "when" clauses break at this point, switch to if-then + + if ($saved_verb eq 'who') { if (verify($from, $password)) { my @whoers; logCommand($from, $line); @@ -1218,10 +1225,10 @@ } } - when ('subscribe') { + elsif ($saved_verb eq 'subscribe') { my $email = shift @cmd; $email = $1 if (defined $email && $email =~/^($addr)/); - + if (verify($from, $password)) { $msg .= subscribe($list, $from, $email); logCommand($from, $line); @@ -1248,7 +1255,7 @@ } } - when ('unsubscribe') { + elsif ($saved_verb eq 'unsubscribe') { my $email = shift @cmd; $email = $1 if (defined $email && $email =~/^($addr)/); @@ -1279,33 +1286,7 @@ } } - # obsoleted by mode ? - if (0) { - when ('suspend' || 'resume') { - if (verify($from, $password) || $conf{security} ne 'paranoid') { - $msg = chgSettings($msg, $_, $list, $from, $from); - logCommand($from, $line); - } - else { genAuth($list, $from, $line, $_); } - } - - # obsoleted by mode ? - when ('maxsize') { - if ((shift @cmd) =~ /^\d+$/) { - if (verify($from, $password) || $conf{security} ne 'paranoid') { - $msg = chgSettings($_, $list, $from, $from, $1); - logCommand($from, $line); - } - else { genAuth($list, $from, $line, $_, $1); } - } - else { - $msg = mt('ERROR:'). ' '. mt('Bad syntax or unknown instruction.'); - break; - } - } - } - - when ('mode') { + elsif ($saved_verb eq 'mode') { my $mode = shift @cmd; unless (defined $mode) { $msg = mt('ERROR:'). ' '. mt('Bad syntax or unknown instruction.'); @@ -1357,7 +1338,7 @@ } } - default { + else { $msg = mt('ERROR:'). ' '. mt('Bad syntax or unknown instruction.'); break; }