Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for given-when bug #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 14 additions & 33 deletions minimalist.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -1248,7 +1255,7 @@
}
}

when ('unsubscribe') {
elsif ($saved_verb eq 'unsubscribe') {
my $email = shift @cmd;
$email = $1 if (defined $email && $email =~/^($addr)/);

Expand Down Expand Up @@ -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.');
Expand Down Expand Up @@ -1357,7 +1338,7 @@
}
}

default {
else {
$msg = mt('ERROR:'). ' '. mt('Bad syntax or unknown instruction.');
break;
}
Expand Down