From: Martin Mareš Date: Sat, 4 Apr 2026 12:37:54 +0000 (+0200) Subject: Get rid of given/when X-Git-Tag: v3.4~1 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=14ed92ed986941f514d2ae1571809d96388ccd90;p=bex.git Get rid of given/when It is going to be removed from Perl 5.42 --- diff --git a/lib/bin/bex-prun b/lib/bin/bex-prun index ba926fd..405564e 100755 --- a/lib/bin/bex-prun +++ b/lib/bin/bex-prun @@ -351,32 +351,27 @@ sub redraw_slot($) { sub update($$$$) { my ($ui, $mach, $jid, $stat) = @_; - given ($stat) { - when ('READY') { + for ($stat) { + if ($_ eq 'READY') { # Pseudo-state generated internally $ui->set_host_status($mach, 'ready'); $ui->set_job_status($mach, $jid, 'ready'); - } - when ('OK') { + } elsif ($_ eq 'OK') { $ui->set_job_status($mach, $jid, 'done'); - } - when (['FAILED', 'INTERR', 'NOPING', 'PREPFAIL', 'NOXFER']) { + } elsif (/^(FAILED|INTERR|NOPING|PREPFAIL|NOXFER)$/) { $ui->set_job_status($mach, $jid, 'failed'); $host_last_fail_job{$mach} = $jid; $host_last_fail_stat{$mach} = $stat; - } - when ('DONE') { + } elsif ($_ eq 'DONE') { if ($job_cnt{$mach}{'failed'}) { $ui->set_host_status($mach, 'failed'); } else { $ui->set_host_status($mach, 'done'); } - } - when ('INIT') { + } elsif ($_ eq 'INIT') { $ui->set_host_status($mach, 'running'); $ui->set_job_status($mach, $jid, 'running') if defined $jid; - } - when ('LOCKED') { + } elsif ($_ eq 'LOCKED') { if (defined $jid) { $ui->set_job_status($mach, $jid, 'failed'); } else { @@ -387,10 +382,8 @@ sub update($$$$) { $host_last_fail_job{$mach} = $jid; $host_last_fail_stat{$mach} = $stat; } - } - when (['START', 'PING', 'PREP', 'SEND', 'RUN']) { - } - default { + } elsif (/^(START|PING|PREP|SEND|RUN)$/) { + } else { $ui->err("Received unknown job status $stat"); } } diff --git a/lib/perl/BEX/Queue.pm b/lib/perl/BEX/Queue.pm index 9bbf505..c272459 100644 --- a/lib/perl/BEX/Queue.pm +++ b/lib/perl/BEX/Queue.pm @@ -236,20 +236,20 @@ sub lock_name($$$) { sub lock($$$) { my ($queue, $machine, $jid) = @_; my $lock; - given ($BEX::Config::locking_scheme) { - when ('queue') { + for ($BEX::Config::locking_scheme) { + if ($_ eq 'queue') { $lock = lock_name($queue, undef, undef); - } - when ('host') { + } elsif ($_ eq 'host') { defined($machine) or return 1; $lock = lock_name($queue, $machine, undef); - } - when ('job') { + } elsif ($_ eq 'job') { defined($machine) && defined($jid) or return 1; $lock = lock_name($queue, $machine, $jid); + } elsif ($_ eq 'none') { + return 1; + } else { + die "Invalid BEX::Config::locking_scheme"; } - when ('none') { return 1; } - default { die "Invalid BEX::Config::locking_scheme"; } } if (defined($queue->{'LockName'})) { return 1 if ($queue->{'LockName'} eq $lock); @@ -275,14 +275,14 @@ sub unlock($) { delete $queue->{'LockName'}; } -# Unsafe (does not check fcntl, only existence of a lock file), but should be enough for `bex ls' +# Unsafe (does not check fcntl, only existence of a lock file), but should be enough for `bex queue' sub is_locked($$$) { my ($queue, $machine, $jid) = @_; - given ($BEX::Config::locking_scheme) { + for ($BEX::Config::locking_scheme) { # Shortcuts - when ('host') { return unless defined $machine; } - when ('jid') { return unless defined $jid; } - when ('none') { return; } + if ($_ eq 'host') { return unless defined $machine; } + elsif ($_ eq 'jid') { return unless defined $jid; } + elsif ($_ eq 'none') { return; } } my $lock = lock_name($queue, $machine, $jid); return -f $lock;