blib/lib/Acme/SList/Scheduler.pm untested

filter: Statementstmt 0.0% 0 / 105 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 152 CC 13 SCAR 38.8
CC
13
Cov
0%
srun
90.0
END
30.0
label
2.0
CRAP 48.6
1 package Acme::SList::Scheduler;
2 $Acme::SList::Scheduler::VERSION = '0.04';
3 use strict;
4 use warnings;
5  
6 require Exporter;
7 our @ISA = qw(Exporter);
8 our @EXPORT = qw(srun label);
9 our @EXPORT_OK = qw();
10  
11 use Getopt::Std;
12 use Acme::SList::Utilities qw(sdate sduration);
13  
14 getopts('e:r:', \my %opts);
15  
16 my $active = (defined($opts{r}) || defined($opts{e})) ? 0 : 1;
17  
18 my $exec = 0;
19 my $aborted = 0;
20  
21 my $act_label = '';
22  
23 END {
24 unless ($aborted) {
25 if ($exec == 0) {
26 my ($rc, $msg);
27  
28 if (defined $opts{e}) { $rc = 242; $msg = "Unable to execute -e $opts{e}"; }
29 elsif (defined $opts{r}) { $rc = 243; $msg = "Unable to restart -r $opts{r}"; }
30 else { $rc = 244; $msg = "No program has been run"; }
31  
32 print "\n========================\n";
33 print "System Error (rc=$rc)\n";
34 printf "$msg\n";
35 print "========================\n";
36 exit $rc;
37 }
38  
39 print "\n";
40 print "+---------------------------------------------------------------+\n";
41 print "| -- SUCCESS --- SUCCESS --- SUCCESS --- SUCCESS --- SUCCESS -- |\n";
42 print "+---------------------------------------------------------------+\n";
43 print "\n";
44 }
45 }
46  
47 sub label {
48 $act_label = $_[0];
49 }
50  
51 sub srun {
52 my ($prog) = @_;
53  
54 if (defined($opts{r}) and $opts{r} eq $act_label) { $active = 1; }
55 if (defined($opts{e})) { $active = $opts{e} eq $act_label; }
56  
57 unless ($active) {
58 print "\n";
59 print "+-------\n";
60 print "| Skipping Program '$prog'...\n";
61 print "+-------\n";
62 return;
63 }
64  
65 $exec++;
66  
67 print "\n";
68 print "+---------------------------------------------------------------+\n";
69 printf "| Program: %-52s |\n", "'$prog'";
70 print "+---------------------------------------------------------------+\n";
71  
72 my $prog_start = time;
73  
74 print "\n";
75 print ">> Start : ", sdate($prog_start), "\n";;
76 print "\n";
77  
78 my $extended = $prog;
79 $extended =~ s{[\(,]}' 'xmsg;
80 $extended =~ s{\)}''xmsg;
81  
82 my $code = system(qq{perl -C${^UNICODE} $extended});
83  
84 my $prog_stop = time;
85  
86 print "\n";
87 print ">> Stop : ", sdate($prog_stop), ", Duration : ", sduration($prog_start, $prog_stop), "\n";;
88  
89 return if $code == 0;
90  
91 $aborted = 1;
92  
93 my ($rc, $msg);
94  
95 if ($code == -1) { $rc = 240; $msg = "Failed to execute: $!"; }
96 elsif ($code & 127) { $rc = 241; $msg = sprintf("Child died with signal %d", ($code & 127)) }
97 else {
98 $rc = $code >> 8;
99  
100 if ($rc == 250) { $msg = "Program '$prog' halted"; }
101 }
102  
103 if ($rc == 250) {
104 print "\n========================\n";
105 print "System Error (rc=$rc)\n";
106 printf "$msg\n";
107 print "========================\n";
108 exit $rc;
109 }
110  
111 print "\n";
112 print "\n";
113 print "*******************************************************************\n";
114 print "*******************************************************************\n";
115 print "*******************************************************************\n";
116 print "*** ***\n";
117 print "*** PROGRAM ABORTED --- PROGRAM ABORTED --- PROGRAM ABORTED ***\n";
118 print "*** ***\n";
119 print "*******************************************************************\n";
120 print "*******************************************************************\n";
121 print "*******************************************************************\n";
122 print "\n";
123 print "Return Code = $rc\n";
124 print "\n";
125  
126 exit $rc;
127 }
128  
129 1;
130  
131 __END__