File Coverage

blib/lib/CA/AutoSys/Status.pm
Criterion Covered Total %
statement 15 38 39.4
branch 0 18 0.0
condition 0 3 0.0
subroutine 5 8 62.5
pod 2 3 66.6
total 22 70 31.4


line stmt bran cond sub pod time code
1             #
2             # $Id: Status.pm 57 2007-10-26 15:10:55Z sini $
3             #
4             # CA::AutoSys - Perl Interface to CA's AutoSys job control.
5             # Copyright (c) 2007 Sinisa Susnjar
6             # See LICENSE for terms of distribution.
7             #
8             # This library is free software; you can redistribute it and/or
9             # modify it under the terms of the GNU Lesser General Public
10             # License as published by the Free Software Foundation; either
11             # version 2.1 of the License, or (at your option) any later version.
12             #
13             # This library is distributed in the hope that it will be useful,
14             # but WITHOUT ANY WARRANTY; without even the implied warranty of
15             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16             # Lesser General Public License for more details.
17             #
18             # You should have received a copy of the GNU Lesser General Public
19             # License along with this library; if not, write to the Free Software
20             # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21             #
22              
23             package CA::AutoSys::Status;
24              
25 1     1   5 use strict;
  1         1  
  1         24  
26 1     1   4 use warnings;
  1         2  
  1         18  
27              
28 1     1   4 use Exporter;
  1         7  
  1         28  
29 1     1   5 use vars qw(@ISA @EXPORT $VERSION);
  1         1  
  1         123  
30             @ISA = qw(Exporter);
31             @EXPORT = qw(&new &format_status &format_time);
32              
33             $VERSION = '1.03';
34              
35             our %status_names = (
36             0 => ' ', # *empty*
37             1 => 'RU', # running
38             2 => ' 2', # *not defined*
39             3 => 'ST', # starting
40             4 => 'SU', # success
41             5 => 'FA', # failure
42             6 => 'TE', # terminated
43             7 => 'OI', # on ice
44             8 => 'IN', # inactive
45             9 => 'AC', # activated
46             10 => 'RE', # restart
47             11 => 'OH', # on hold
48             12 => 'QW', # queue wait
49             13 => '13', # *not defined*
50             14 => 'RD', # refresh dependencies
51             15 => 'RF', # refresh filewatcher
52             );
53              
54             use constant {
55 1         561 NONE => 0,
56             RUNNING => 1,
57             UNDEF_2 => 2,
58             STARTING => 3,
59             SUCCESS => 4,
60             FAILURE => 5,
61             TERMINATED => 6,
62             ON_ICE => 7,
63             INACTIVE => 8,
64             ACTIVATED => 9,
65             RESTART => 10,
66             ON_HOLD => 11,
67             QUEUE_WAIT => 12,
68             UNDEF_13 => 13,
69             REFRESH_DEP => 14,
70             REFRESH_FW => 15
71 1     1   4 };
  1         2  
72              
73             our %long_status = (
74             0 => "NONE",
75             1 => "RUNNING",
76             2 => "UNDEF_2",
77             3 => "STARTING",
78             4 => "SUCCESS",
79             5 => "FAILURE",
80             6 => "TERMINATED",
81             7 => "ON_ICE",
82             8 => "INACTIVE",
83             9 => "ACTIVATED",
84             10 => "RESTART",
85             11 => "ON_HOLD",
86             12 => "QUEUE_WAIT",
87             13 => "UNDEF_13",
88             14 => "REFRESH_DEP",
89             15 => "REFRESH_FW"
90             );
91              
92             sub new {
93 0     0 0   my $self = {};
94 0           my $class = shift();
95              
96 0 0         if (@_) {
97 0           my %args = @_;
98 0 0         $self->{last_start} = $args{last_start} ? $args{last_start} : undef;
99 0 0         $self->{last_end} = $args{last_end} ? $args{last_end} : undef;
100 0 0         $self->{status} = $args{status} ? $args{status} : undef;
101 0 0         $self->{status_time} = $args{status_time} ? $args{status_time} : undef;
102 0           $self->{name} = $long_status{$self->{status}};
103 0 0         $self->{run_num} = $args{run_num} ? $args{run_num} : undef;
104 0 0         $self->{ntry} = $args{ntry} ? $args{ntry} : undef;
105 0 0         $self->{exit_code} = $args{exit_code} ? $args{exit_code} : undef;
106             }
107              
108 0           bless($self);
109 0           return $self;
110             } # new()
111              
112             sub format_status {
113 0     0 1   my $status = shift();
114 0           return $status_names{$status};
115             } # format_status()
116              
117             sub format_time {
118 0     0 1   my $time = shift();
119 0 0 0       if (!defined($time) || $time == 999999999) {
120 0           return "-----";
121             }
122 0           my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = localtime($time);
123 0           $mon++;
124 0           $year += 1900;
125 0           return sprintf("%02d/%02d/%04d %02d:%02d:%02d", $mon, $mday, $year, $hour, $min, $sec);
126             # return sprintf("%02d/%02d/%04d %02d:%02d:%02d (%d)", $mon, $mday, $year, $hour, $min, $sec, $time);
127             } # format_time()
128              
129             1;
130              
131             __END__