blib/lib/HPCI/CommandScript.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 57 CC 5 SCAR 27.7
CC
5
Cov
0%
_build_script_file
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 16.0
1 package HPCI::CommandScript;
2  
3 ### INCLUDES ######################################################################################
4  
5 # safe Perl
6 use warnings;
7 use strict;
8 use Carp;
9  
10 use Moose::Role;
11 use MooseX::Types::Path::Class qw(Dir File);
12  
13 sub _build_script_file {
14 my $self = shift;
15 my $csn = $self->script_file;
16 unless ($self->_script_file_built) {
17 $self->_script_file_built(1);
18 open my $fh, '>', $csn
19 or $self->_croak("Cannot create script ($csn): $!");
20 print $fh '#!', $self->command_shell, "\n",
21 "\n",
22 "set -x\n",
23 "# This autogenerated script is to be run on a ", $self->cluster, " cluster.\n",
24 "\n",
25 ;
26  
27 for my $meth (@{ $self->_command_expansion_methods }) {
28 $self->$meth($fh) if $self->can($meth);
29 }
30  
31 $self->print_pre_commands($fh) if $self->can('print_pre_commands');
32  
33 print $fh $self->command, "\n";
34  
35 $self->print_post_commands($fh) if $self->can('print_post_commands');
36  
37 close $fh;
38 chmod(0755, $csn);
39  
40 $self->info("Rendered: '$csn'\n");
41 }
42 return;
43 };
44  
45 has 'script_file' => (
46 is => 'ro',
47 isa => File,
48 coerce => 1,
49 lazy => 1,
50 default => sub {
51 my $self = shift;
52 return $self->stage_dir->file( 'script.sh' );
53 },
54 );
55  
56 has '_script_file_built' => (
57 is => 'rw',
58 isa => 'Int',
59 init_arg => undef,
60 default => 0,
61 );
62  
63 has '_command_expansion_methods' => (
64 is => 'rw',
65 isa => 'ArrayRef[Str]',
66 lazy => 1,
67 init_arg => undef,
68 default => sub { [ 'print_env_settings' ] },
69 );
70  
71 has 'command_shell' => (
72 is => 'ro',
73 isa => 'Str',
74 lazy => 1,
75 default => '/bin/bash',
76 );
77  
78 1;