]> mj.ucw.cz Git - bex.git/commitdiff
Get rid of given/when
authorMartin Mareš <mj@ucw.cz>
Sat, 4 Apr 2026 12:37:54 +0000 (14:37 +0200)
committerMartin Mareš <mj@ucw.cz>
Sat, 4 Apr 2026 12:37:54 +0000 (14:37 +0200)
It is going to be removed from Perl 5.42

lib/bin/bex-prun
lib/perl/BEX/Queue.pm

index ba926fd4e4abd1b5407ba4c37a69c346a2321ac5..405564e3ad28b6bb7b2f6c4e2b8148339604872f 100755 (executable)
@@ -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");
                }
        }
index 9bbf505036bc1efa92e38d1143280243d130b796..c272459b230262267b536b90366ba8cdc5bd19c6 100644 (file)
@@ -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;