| 1 | package Csistck::Test::Script; | ||||||||||||
| 2 | |||||||||||||
| 3 | 17 | ▶ | use 5.010; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 17 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 17 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 17 | ▶ | use base 'Csistck::Test'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 17 | ▶ | use Csistck::Oper qw/debug/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 17 | ▶ | use Csistck::Config qw/option/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 17 | our @EXPORT_OK = qw/script/; | |||||||||||
| 12 | |||||||||||||
| 13 | 17 | ▶ | use Digest::MD5; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 17 | ▶ | use File::Basename; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 17 | ▶ | use FindBin; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | |||||||||||||
| 17 | 17 | ▶ | use constant MODE_CHECK => 'check'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 17 | ▶ | use constant MODE_REPAIR => 'run'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | |||||||||||||
| 20 | # Use the convenience function to normalize args | ||||||||||||
| 21 | sub script { | ||||||||||||
| 22 | 3 | ▶ | my $script = shift; | ||||||||||
|
Subroutine
script: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 23 | 3 | ▶ | my $script_args = shift // []; | ||||||||||
|
Condition100%2/2
shift() // []
MC/DC100%1/1
shift() // []
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 24 | 3 | ▶ | my %args = ( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 25 | args => (ref $script_args eq 'ARRAY') ? | ||||||||||||
| 26 | $script_args : | ||||||||||||
| 27 | [$script_args], | ||||||||||||
| 28 | @_ | ||||||||||||
| 29 | ); | ||||||||||||
| 30 | 3 | Csistck::Test::Script->new($script, %args); | |||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | 20 | ▶ | sub script_name { shift->{target}; } | ||||||||||
|
Subroutine
script_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 34 | 8 | ▶ | sub args { shift->{args}; } | ||||||||||
|
Subroutine
args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 35 | |||||||||||||
| 36 | # Wrap common process function | ||||||||||||
| 37 | 12 | ▶ | sub desc { return sprintf("Script test for %s", shift->script_name); } | ||||||||||
|
Subroutine
desc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 38 | 6 | ▶ | sub check { shift->process(MODE_CHECK); } | ||||||||||
|
Subroutine
check: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 39 | 2 | ▶ | sub repair { shift->process(MODE_REPAIR); } | ||||||||||
|
Subroutine
repair: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 40 | |||||||||||||
| 41 | sub process { | ||||||||||||
| 42 | 8 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
process: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 43 | 8 | my $mode = shift; | |||||||||||
| 44 | 8 | my $script = $self->script_name; | |||||||||||
| 45 | # Args was passed as arrayref | ||||||||||||
| 46 | 8 | my @args = @{$self->args}; | |||||||||||
| 47 | |||||||||||||
| 48 | # TODO sanity check on script | ||||||||||||
| 49 | |||||||||||||
| 50 | # Build command | ||||||||||||
| 51 | 8 | my @command = ($script, $mode, @args); | |||||||||||
| 52 | 8 | debug(sprintf("Run command: cmd=<%s>", join(" ", @command))); | |||||||||||
| 53 | 8 | chdir($FindBin::Bin); | |||||||||||
| 54 | 8 | my $ret = system(@command); | |||||||||||
| 55 | |||||||||||||
| 56 | 8 | ▶ | return (($ret == 0) ? $self->pass('Command passed') : | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | $self->fail('Command failed')); | ||||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | 17 | 1; | |||||||||||
| 61 | __END__ | ||||||||||||