| 1 | package Makerelease::Step::Perl; | ||
| 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 | return $self->expand_parameters($command); | ||
| 21 | } | ||
| 22 | |||
| 23 | sub test { | ||
| 24 | my ($self, $step, $parentstep, $counter) = @_; | ||
| 25 | return 1 if ($self->require_piece($step, $parentstep, $counter, | ||
| 26 | 'perl', 'code')); | ||
| 27 | return 0; | ||
| 28 | } | ||
| 29 | |||
| 30 | sub step { | ||
| 31 | my ($self, $step, $parentstep, $counter) = @_; | ||
| 32 | |||
| 33 | foreach my $code (@{$step->{'perl'}[0]{'code'}}) { | ||
| 34 | my $status = 1; | ||
| 35 | |||
| 36 | # run it till we get a succeesful result or they bail on us | ||
| 37 | |||
| 38 | while ($status ne '0') { | ||
| 39 | |||
| 40 | $self->output("evaluating specified perl code"); | ||
| 41 | $status = eval $code; | ||
| 42 | if ($@) { | ||
| 43 | print STDERR "error evaluating code in Step $parentstep$counter: $@\n"; | ||
| 44 | } | ||
| 45 | |||
| 46 | if ($status ne 0 ) { | ||
| 47 | # command failed, prompt for what to do? | ||
| 48 | my $dowhat = ''; | ||
| 49 | |||
| 50 | while ($dowhat eq '') { | ||
| 51 | $dowhat = | ||
| 52 | $self->getinput("failed: status=$? what now (c,r,q)?"); | ||
| 53 | |||
| 54 | # if answered: | ||
| 55 | # c => continue | ||
| 56 | # q => quit | ||
| 57 | if ($dowhat eq 'c') { | ||
| 58 | $status = 0; | ||
| 59 | } elsif ($dowhat eq 'q') { | ||
| 60 | $self->output("Quitting at step '$parentstep$counter' as requested"); | ||
| 61 | exit 1; | ||
| 62 | } elsif ($dowhat eq 'r') { | ||
| 63 | $self->output("-- re-running ----------"); | ||
| 64 | } else { | ||
| 65 | $self->output("unknown response: $dowhat"); | ||
| 66 | $dowhat = ''; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | $self->output("\n"); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | sub document_step { | ||
| 76 | my ($self, $step, $parentstep, $counter) = @_; | ||
| 77 | |||
| 78 | $self->output("Internal perl code will be executed"); | ||
| 79 | } | ||
| 80 | |||
| 81 | 1; | ||
| 82 |