blib/lib/HPC/Runner/Command/Utils/Base.pm

filter: Statementstmt 37.1% 26 / 70 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 54.5% 6 / 11 Podpod 100% 4 / 4 totaltotal 32.7% 36 / 110 CC 12 SCAR 29.8
CC
12
Cov
28%
set_basedir
42.0
git_things
30.0
set_outdir
6.0
CRAP 19.7
« blib/lib/HPC/Runner/Command/submit_jobs/Utils/Scheduler/ResolveDeps.pm ↑ Summary blib/lib/HPC/Runner/Command/submit_jobs/Plugin/SGE.pm »
1 package HPC::Runner::Command::Utils::Base;
2  
3 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use File::Path qw(make_path remove_tree);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use List::Uniq ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use MooseX::App::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use MooseX::Types::Path::Tiny qw/Path Paths AbsPath AbsFile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 HPC::Runner::Command::Utils::Base
12  
13 Base class for HPC::Runner::Command libraries.
14  
15 This is a Moose Role. To use in any another applications or plugins call as
16  
17 package MyApp;
18  
19 use Moose;
20 with 'HPC::Runner::Command::Utils::Base';
21  
22 =head2 Command Line Options
23  
24  
25 =head3 infile
26  
27 File of commands separated by newline. The command 'wait' indicates all previous commands should finish before starting the next one.
28  
29 =cut
30  
31 1 option 'infile' => (
32 is => 'rw',
33 required => 1,
34 documentation =>
35 q{File of commands separated by newline. The command 'wait' indicates all previous commands should finish before starting the next one.},
36 isa => AbsFile,
37 coerce => 1,
38 cmd_aliases => ['i'],
39 );
40  
41 =head3 outdir
42  
43 Directory to write out files and optionally, logs.
44  
45 =cut
46  
47 1 option 'outdir' => (
48 is => 'rw',
49 isa => AbsPath,
50 lazy => 1,
51 coerce => 1,
52 required => 1,
53 default => \&set_outdir,
54 documentation => q{Directory to write out files.},
55 trigger => \&_make_the_dirs,
56 predicate => 'has_outdir',
57 );
58  
59 1 option 'basedir' => (
60 is => 'rw',
61 isa => AbsPath,
62 lazy => 1,
63 coerce => 1,
64 required => 1,
65 default => \&set_basedir,
66 documentation => q{Base directory to write out files.},
67 trigger => \&_make_the_dirs,
68 predicate => 'has_basedir',
69 );
70  
71 #These two should both be in execute_jobs
72  
73 =head3 procs
74  
75 Total number of concurrent running tasks.
76  
77 Analagous to parallel --jobs i
78  
79 =cut
80  
81 1 option 'procs' => (
82 is => 'rw',
83 isa => 'Int',
84 default => 1,
85 required => 0,
86 documentation =>
87 q{Total number of concurrently running jobs allowed at any time.}
88 );
89  
90 1 option 'poll_time' => (
91 is => 'rw',
92 isa => 'Num',
93 documentation =>
94 'Time in seconds to poll the process for memory profiling.',
95 default => 5,
96 cmd_aliases => ['pt'],
97 );
98  
99 1 option 'memory_diff' => (
100 is => 'rw',
101 isa => 'Num',
102 documentation => 'Difference from last memory profile in order to record.',
103 default => 0.10,
104 cmd_aliases => ['md'],
105 );
106  
107 =head2 Attributes
108  
109 =cut
110  
111 1 has 'cmd' => (
112 traits => ['String'],
113 is => 'rw',
114 isa => 'Str',
115 required => 0,
116 handles => {
117 add_cmd => 'append',
118 match_cmd => 'match',
119 },
120 predicate => 'has_cmd',
121 clearer => 'clear_cmd',
122 );
123  
124 =head3 set_basedir
125  
126 =cut
127  
128 sub set_basedir {
129 0 ▶ my $self = shift;
Subroutine set_basedir: not called CC=6 SCAR=37.4
Pod documented
130  
131 0 ▶ if ( $self->has_basedir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_basedir) 0 0 0
132 0 make_path( $self->basedir );
133 0 return;
134 }
135  
136 0 my $dt = $self->dt;
137 0 $dt = "$dt";
138 0 $dt =~ s/:/-/g;
139  
140 0 my $outdir;
141 0 ▶ if ( $self->has_version && $self->has_git ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_version and $self->has_git) { } 0 0 0
Condition0%0/3
$self->has_version and $self->has_git
!ll&&!rl&&r
000
MC/DC0%0/2
$self->has_version and $self->has_git
$self->has_version $self->has_git
Truth table0%0/3
A and B
A= $self->has_versionB= $self->has_git
ABresult
0X0
100
111
142 0 ▶ if ( $self->has_project ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_project) { } 0 0 0
143 0 $outdir =
144 File::Spec->catdir( 'hpc-runner', $self->project, $dt,
145 $self->version, );
146 }
147 else {
148 0 $outdir = File::Spec->catdir( 'hpc-runner', $dt, $self->version, );
149 }
150 }
151 else {
152 0 ▶ if ( $self->has_project ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_project) { } 0 0 0
153 0 $outdir = File::Spec->catdir( 'hpc-runner', $dt, $self->project, );
154 }
155 else {
156 0 $outdir = File::Spec->catdir( 'hpc-runner', $dt );
157 }
158 }
159  
160 0 make_path($outdir);
161  
162 0 return $outdir;
163 }
164  
165 =head3 set_outdir
166  
167 Internal variable
168  
169 =cut
170  
171 ##Why is this different from set logdir?
172  
173 sub set_outdir {
174 0 ▶ my $self = shift;
Subroutine set_outdir: not called CC=2 SCAR=17.9
Pod documented
175  
176 0 ▶ if ( $self->has_outdir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_outdir) 0 0 0
177 0 $self->_make_the_dirs( $self->outdir );
178 0 return;
179 }
180  
181 0 my $outdir = File::Spec->catdir($self->basedir, 'scratch');
182  
183 0 make_path($outdir);
184  
185 0 return $outdir;
186 }
187  
188 =head3 make_the_dirs
189  
190 Make any necessary directories
191  
192 =cut
193  
194 sub _make_the_dirs {
195 0 ▶ my ( $self, $outdir ) = @_;
Subroutine _make_the_dirs: not called CC=2 SCAR=17.9
196  
197 0 ▶ make_path($outdir) unless -d $outdir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $outdir 0 0 0
198 }
199  
200 =head3 datetime_now
201  
202 =cut
203  
204 sub datetime_now {
205 0 ▶ my $self = shift;
Subroutine datetime_now: not called CC=1 SCAR=6.9
Pod documented
206  
207 0 my $dt = DateTime->now( time_zone => 'local' );
208  
209 0 my $ymd = $dt->ymd();
210 0 my $hms = $dt->hms();
211  
212 0 return ( $dt, $ymd, $hms );
213 }
214  
215 =head3 git_things
216  
217 Get git versions, branch, and tags
218  
219 =cut
220  
221 sub git_things {
222 0 ▶ my $self = shift;
Subroutine git_things: not called CC=5 SCAR=34.0
Pod documented
223  
224 0 $self->init_git;
225 0 $self->dirty_run;
226 0 $self->git_info;
227  
228 0 ▶ return unless $self->has_git;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_git 0 0 0
229  
230 0 ▶ return unless $self->has_version;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_version 0 0 0
231  
232 0 ▶ if ( $self->tags ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tags) { } 0 0 0
233 0 ▶ push( @{ $self->tags }, "$self->{version}" ) if $self->has_version;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_version 0 0 0
234 }
235 else {
236 0 $self->tags( [ $self->version ] );
237 }
238 0 my @tmp = uniq( @{ $self->tags } );
239 0 $self->tags( \@tmp );
240 }
241  
242 1 1;
« blib/lib/HPC/Runner/Command/submit_jobs/Utils/Scheduler/ResolveDeps.pm ↑ Summary blib/lib/HPC/Runner/Command/submit_jobs/Plugin/SGE.pm »