JPRED-2 Move Jpred 3.0.1 to public Git
[jpred.git] / jpred / lib / Run.pm
1 package Run;
2
3 use strict;
4 use warnings;
5 use Carp;
6
7 use Exporter;
8 use POSIX qw(WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG);
9
10 our @ISA = qw(Exporter);
11 our @EXPORT_OK = qw(check);
12
13 sub check {
14         my ($prog, $status) = @_;
15
16         if ($status == 0) {
17                 return 1;
18         }
19         elsif ($status == -1) {
20                 croak "$prog executable not found\n";
21         }
22         elsif (WIFEXITED($status) and WEXITSTATUS($status)) {
23                 croak "$prog exited with status ".WEXITSTATUS($status)."\n";
24         }
25         elsif (WIFSIGNALED($status)) {
26                 croak "$prog halted by external signal ".WTERMSIG($status)."\n";
27         }
28         else {
29                 croak "$prog suffered from a random pantwetting event";
30         }
31 }
32
33 1;