lib/Rex/Interface/Executor/Default.pm

filter: Statementstmt 94.9% 56 / 59 Branchbran 78.5% 11 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 86.5% 77 / 89 CC 9 SCAR 15.0
CC
9
Cov
89%
exec
8.2
new
2.1
BEGIN
1.0
CRAP 4.5
« lib/Rex/Cloud.pm ↑ Summary lib/Rex/Helper/System.pm »
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
l!l&&r!l&&!r
02130
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($wantarray) { } 1 53 54
47 1 ▶ if ( ref $opts eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts eq 'ARRAY') { } 1 0 1
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
BranchTrueFalseTotal
if (ref $opts eq 'ARRAY') { } 13 40 53
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
BranchTrueFalseTotal
if ($error) { } 7 47 54
70 7 ▶ if ( exists $opts{o} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{'o'}) { } 0 7 7
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
BranchTrueFalseTotal
if (exists $opts{"o"}) 0 47 47
81 0 Rex::Output->get->add( $task->name );
82 }
83 }
84  
85 47 ▶ if ($wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantarray) { } 1 46 47
86 1 return @ret;
87 }
88 else {
89 46 return $ret[0];
90 }
91 }
92  
93 55 1;
« lib/Rex/Cloud.pm ↑ Summary lib/Rex/Helper/System.pm »