| 1 | # | ||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||
| 3 | # | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Rex::Interface::Executor::Default; | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 55 | ▶ | use v5.14.4; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 55 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 55 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 55 | ▶ | use Rex::Hook; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 55 | ▶ | use Rex::Logger; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 55 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 55 | ▶ | use Rex::Interface::Executor::Base; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 55 | ▶ | use base qw(Rex::Interface::Executor::Base); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 55 | require Rex::Args; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 213 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||
| 22 | 213 | my $that = shift; | |||||||||||||||||||
| 23 | 213 | ▶ | my $proto = ref($that) || $that; | ||||||||||||||||||
|
Condition33%1/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table33%1/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 24 | 213 | my $self = {@_}; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 213 | bless( $self, $proto ); | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 213 | return $self; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 54 | ▶ | sub exec { | ||||||||||||||||||
|
Subroutine
exec: called CC=8 SCAR=21.0
Pod
undocumented
| |||||||||||||||||||||
| 32 | 54 | my ( $self, $opts, $args ) = @_; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 54 | my $task = $self->{task}; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 54 | Rex::Logger::debug( "Executing " . $task->name ); | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 54 | my $wantarray = wantarray; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 54 | my @ret; | |||||||||||||||||||
| 41 | 54 | eval { | |||||||||||||||||||
| 42 | 54 | my $code = $task->code; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 54 | Rex::Hook::run_hook( task => "before_execute", $task->name, @_ ); | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 54 | ▶ | if ($wantarray) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 1 | ▶ | if ( ref $opts eq "ARRAY" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 1 | @ret = $code->( @{$opts} ); | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||
| 51 | 0 | @ret = $code->( $opts, $args ); | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | else { | ||||||||||||||||||||
| 55 | 53 | ▶ | if ( ref $opts eq "ARRAY" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 13 | $ret[0] = $code->( @{$opts} ); | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||
| 59 | 40 | $ret[0] = $code->( $opts, $args ); | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 47 | Rex::Hook::run_hook( task => "after_execute", $task->name, @_ ); | |||||||||||||||||||
| 64 | }; | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 54 | my $error = $@; | |||||||||||||||||||
| 67 | 54 | my %opts = Rex::Args->getopts; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 54 | ▶ | if ($error) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | 7 | ▶ | if ( exists $opts{o} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | 0 | Rex::Output->get->add( $task->name, error => 1, msg => $error ); | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||
| 74 | 7 | Rex::Logger::info( "Error executing task:", "error" ); | |||||||||||||||||||
| 75 | 7 | Rex::Logger::info( "$error", "error" ); | |||||||||||||||||||
| 76 | 7 | die($error); | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||
| 80 | 47 | ▶ | if ( exists $opts{o} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | 0 | Rex::Output->get->add( $task->name ); | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 47 | ▶ | if ($wantarray) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 86 | 1 | return @ret; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||
| 89 | 46 | return $ret[0]; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 55 | 1; | |||||||||||||||||||