Makerelease/Step/Command.pm untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 79 CC 9 SCAR 34.1
CC
9
Cov
0%
step
56.0
get_command_string
6.0
test
6.0
CRAP 30.1
1 package Makerelease::Step::Command;
2  
3 use strict;
4 use Makerelease::Step;
5  
6 our $VERSION = '0.1';
7  
8 our @ISA=qw(Makerelease::Step);
9  
10 sub get_command_string {
11 my ($self, $commandstart) = @_;
12  
13 my $command;
14  
15 if (ref($commandstart) eq 'HASH') {
16 $command = $commandstart->{'content'};
17 } else {
18 $command = $commandstart;
19 }
20 $command =~ s/^\s*//;
21 $command =~ s/\s*$//;
22 return $self->expand_parameters($command);
23 }
24  
25 sub test {
26 my ($self, $step, $parentstep, $counter) = @_;
27 return 1 if ($self->require_piece($step, $parentstep, $counter,
28 'commands', 'command'));
29 return 0;
30 }
31  
32 sub step {
33 my ($self, $step, $parentstep, $counter) = @_;
34  
35 foreach my $command (@{$step->{'commands'}[0]{'command'}}) {
36 my $status = 1;
37  
38 # run it till we get a succeesful result or they bail on us
39
40 while ($status ne '0') {
41  
42 my $ignoreerror = 0;
43 $ignoreerror = 1
44 if (ref($command) eq 'HASH' && $command->{'ignoreerror'});
45  
46 my $cmdstr = $self->get_command_string($command);
47  
48 $self->output("running '$cmdstr'");
49 system("$cmdstr");
50 $status = $?;
51 $status = 0 if ($ignoreerror);
52  
53 if ($status ne 0 ) {
54 # command failed, prompt for what to do?
55 my $dowhat = '';
56  
57 while ($dowhat eq '') {
58 $dowhat =
59 $self->getinput("failed: status=$? what now (c,r,q)?");
60
61 # if answered:
62 # c => continue
63 # q => quit
64 if ($dowhat eq 'c') {
65 $status = 0;
66 } elsif ($dowhat eq 'q') {
67 $self->output("Quitting at step '$parentstep$counter' as requested");
68 exit 1;
69 } elsif ($dowhat eq 'r') {
70 $self->output("-- re-running ----------");
71 } else {
72 $self->output("unknown response: $dowhat");
73 $dowhat = '';
74 }
75 }
76 }
77 $self->output("");
78 }
79 }
80 }
81  
82 sub document_step {
83 my ($self, $step, $parentstep, $counter) = @_;
84  
85 $self->output("Commands to execute:");
86 foreach my $command (@{$step->{'commands'}[0]{'command'}}) {
87 $self->output(" " . $self->get_command_string($command));
88 }
89 }
90  
91 1;
92