blib/lib/HPC/Runner/Command/submit_jobs/Utils/Plugin.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 87 CC 11 SCAR 34.2
CC
11
Cov
0%
create_plugin_str
56.0
unparse_plugin_opts
20.0
hpc_load_plugins
6.0
CRAP 30.6
1 package HPC::Runner::Command::submit_jobs::Utils::Plugin;
2  
3 use MooseX::App::Role;
4 use namespace::autoclean;
5 use List::MoreUtils qw(first_index indexes uniq);
6  
7 with 'MooseX::Object::Pluggable';
8  
9 =head3 hpc_plugins
10  
11 Load hpc_plugins. PBS, Slurm, Web, etc.
12  
13 =cut
14  
15 option 'hpc_plugins' => (
16 is => 'rw',
17 isa => 'ArrayRef[Str]',
18 documentation => 'Load hpc_plugins',
19 cmd_split => qr/,/,
20 required => 0,
21 default => sub { return ['Slurm'] },
22 );
23  
24 option 'hpc_plugins_opts' => (
25 is => 'rw',
26 isa => 'HashRef',
27 documentation => 'Options for hpc_plugins',
28 required => 0,
29 default => sub { {} },
30 );
31  
32 =head3 hpc_load_plugins
33  
34 =cut
35  
36 sub hpc_load_plugins {
37 my $self = shift;
38  
39 return unless $self->hpc_plugins;
40  
41 $self->app_load_plugins( $self->hpc_plugins );
42 $self->parse_plugin_opts( $self->hpc_plugins_opts );
43 }
44  
45 after 'hpc_load_plugins' => sub {
46 my $self = shift;
47  
48 if ( $self->has_config_files ) {
49 $self->load_configs;
50 }
51 };
52  
53 =head3 create_plugin_str
54  
55 Make sure to pass plugins to job runner
56  
57 =cut
58  
59 sub create_plugin_str {
60 my $self = shift;
61  
62 my $plugin_str = "";
63  
64 ##TODO Update this if we don't have plugin strings
65 if ( $self->has_job_plugins ) {
66 my @uniq = uniq( @{ $self->job_plugins } );
67 $self->job_plugins( \@uniq );
68 $plugin_str .= " \\\n\t";
69 $plugin_str .= "--job_plugins " . join( ",", @{ $self->job_plugins } );
70  
71 $plugin_str .= " \\\n\t" if $self->job_plugins_opts;
72 $plugin_str .=
73 $self->unparse_plugin_opts( $self->job_plugins_opts, 'job_plugins' )
74 if $self->job_plugins_opts;
75 }
76  
77 if ( $self->has_plugins ) {
78 my @uniq = uniq( @{ $self->job_plugins } );
79 $self->job_plugins( \@uniq );
80 $plugin_str .= " \\\n\t";
81 $plugin_str .= "--plugins " . join( ",", @{ $self->plugins } );
82 $plugin_str .= " \\\n\t" if $self->plugins_opts;
83 $plugin_str .=
84 $self->unparse_plugin_opts( $self->plugins_opts, 'plugins' )
85 if $self->plugins_opts;
86 }
87  
88 return $plugin_str;
89 }
90  
91 sub unparse_plugin_opts {
92 my $self = shift;
93 my $opt_href = shift;
94 my $opt_opt = shift;
95  
96 my $opt_str = "";
97  
98 return unless $opt_href;
99  
100 #Get the opts
101  
102 while ( my ( $k, $v ) = each %{$opt_href} ) {
103 next unless $k;
104 $v = "" unless $v;
105 $opt_str .= "--$opt_opt" . "_opts " . $k . "=" . $v . " ";
106 }
107  
108 return $opt_str;
109 }
110  
111 1;