blib/lib/XAS/Lib/Batch.pm untested

filter: Statementstmt 0.0% 0 / 18 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 27 CC 2 SCAR 13.9
CC
2
Cov
0%
do_cmd
6.0
init
2.0
BEGIN
2.0
CRAP 4.0
1 package XAS::Lib::Batch;
2  
3 our $VERSION = '0.01';
4  
5 use XAS::Class
6 debug => 0,
7 version => $VERSION,
8 base => 'XAS::Base',
9 utils => 'dotid run_cmd trim',
10 vars => {
11 PARAMS => {
12 -interface => { optional => 1, default => 'XAS::Lib::Batch::Interface::Torque' },
13 }
14 }
15 ;
16  
17 #use Data::Dumper;
18  
19 # ----------------------------------------------------------------------
20 # Public Methods
21 # ----------------------------------------------------------------------
22  
23 # ----------------------------------------------------------------------
24 # Private Methods
25 # ----------------------------------------------------------------------
26  
27 sub do_cmd {
28 my $self = shift;
29 my ($cmd, $sub) = $self->validate_params(\@_, [1,1]);
30  
31 $self->log->debug("command = $cmd");
32  
33 my ($output, $rc, $sig) = run_cmd($cmd);
34  
35 if ($rc != 0) {
36  
37 my $msg = $output->[0] || '';
38  
39 $self->throw_msg(
40 dotid($self->class) . ".$sub",
41 'pbserr',
42 $rc, trim($msg)
43 );
44  
45 }
46  
47 return $output;
48  
49 }
50  
51 sub init {
52 my $class = shift;
53  
54 my $self = $class->SUPER::init(@_);
55  
56 $self->class->mixin($self->interface);
57  
58 return $self;
59  
60 }
61  
62 1;
63  
64 __END__
65  
66 =head1 NAME
67  
68 XAS::Lib::Batch - A class for the XAS environment
69  
70 =head1 SYNOPSIS
71  
72 use XAS::Class
73 version => '0.01',
74 base => 'XAS::Lib::Batch'
75 ;
76  
77 =head1 DESCRIPTION
78  
79 This is a class for accessing a batch system. Batch systems are a controlled
80 way to run jobs in the background. Depending on how the batch system is
81 setup you may have access to hundreds of systems to run jobs on. These jobs
82 can then controlled by issuing commads against the batch system. This module
83 encapsulates those commands into Perl objects and methods.
84  
85 There is apparently a standardized command line interface to these batch
86 systems. This module also helps to abstract some of the differences between
87 those standardized commands. Because if you work in this business long enough
88 you get to know what "standardized" really means.
89  
90 Since this is Perl and you are loading a mixin. You could access the mixin
91 methods directly. But it is advisable to use the pre-defined classes to help
92 with parameter checking and exception handling.
93  
94 =head1 METHODS
95  
96 =head2 new
97  
98 This initializes the class and takes these parameters:
99  
100 =over 4
101  
102 =item B<-interface>
103  
104 This defines the interface to load. It defaults to L<XAS::Lib::Batch::Interface::Torque|XAS::Lib::Batch::Interface::Torque>.
105  
106 =back
107  
108 =head2 do_cmd($command)
109  
110 This method will run a command and capture its output. If an non zero return
111 code is detected, it will throw an exception with that return code and the
112 first output line returned.
113  
114 =over 4
115  
116 =item B<$command>
117  
118 The command to execute in the background using Perl's backtick function. STDERR
119 is redirected into STDOUT.
120  
121 =back
122  
123 =head1 SEE ALSO
124  
125 =over 4
126  
127 =item L<XAS|XAS>
128  
129 =back
130  
131 =head1 AUTHOR
132  
133 Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
134  
135 =head1 COPYRIGHT AND LICENSE
136  
137 Copyright (c) 2015 Kevin L. Esteb
138  
139 This is free software; you can redistribute it and/or modify it under
140 the terms of the Artistic License 2.0. For details, see the full text
141 of the license at http://www.perlfoundation.org/artistic_license_2_0.
142  
143 =cut