• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RexOps / Rex / 20369324708

14 Nov 2025 09:23PM UTC coverage: 51.073% (+0.04%) from 51.03%
20369324708

push

github

ferki
Keep testing with perl-5.40

10117 of 19809 relevant lines covered (51.07%)

100.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.12
/lib/Rex/Interface/Exec/Base.pm
1
#
2
# (c) Jan Gehring <jan.gehring@gmail.com>
3
#
4

5
package Rex::Interface::Exec::Base;
6

7
use v5.14.4;
69✔
8
use warnings;
69✔
9
use Carp;
69✔
10
use Rex::Helper::Run;
69✔
11
use Rex::Commands::Fs;
69✔
12
use Rex::Interface::Shell;
69✔
13

14
our $VERSION = '9999.99.99_99'; # VERSION
15

16
sub new {
17
  my $that  = shift;
×
18
  my $proto = ref($that) || $that;
×
19
  my $self  = {@_};
×
20

21
  bless( $self, $proto );
×
22

23
  return $self;
×
24
}
25

26
sub exec { die("Must be implemented by Interface Class"); }
×
27

28
sub _continuous_read {
29
  my ( $self, $line, $option ) = @_;
4,500✔
30
  my $cb = $option->{continuous_read} || undef;
4,500✔
31

32
  if ( defined($cb) && ref($cb) eq 'CODE' ) {
4,500✔
33
    &$cb($line);
×
34
  }
35
}
36

37
sub _end_if_matched {
38
  my ( $self, $line, $option ) = @_;
4,500✔
39
  my $regex = $option->{end_if_matched} || undef;
4,500✔
40

41
  if ( defined($regex) && ref($regex) eq 'Regexp' && $line =~ m/$regex/ ) {
4,500✔
42
    return 1;
×
43
  }
44
  return;
4,500✔
45
}
46

47
sub execute_line_based_operation {
48
  my ( $self, $line, $option ) = @_;
4,500✔
49

50
  $self->_continuous_read( $line, $option );
4,500✔
51
  return $self->_end_if_matched( $line, $option );
4,500✔
52
}
53

54
sub can_run {
55
  my ( $self, $commands_to_check, $check_with_command ) = @_;
586✔
56

57
  $check_with_command ||= "command -v";
586✔
58

59
  my $exec  = Rex::Interface::Exec->create;
586✔
60
  my $cache = Rex::get_cache();
586✔
61

62
  for my $command ( @{$commands_to_check} ) {
586✔
63

64
    my $cache_key_name = $cache->gen_key_name("can_run.cmd/$command");
587✔
65
    if ( $cache->valid($cache_key_name) ) {
587✔
66
      return $cache->get($cache_key_name);
4✔
67
    }
68

69
    my @output = Rex::Helper::Run::i_run "$check_with_command $command",
583✔
70
      fail_ok => 1;
71

72
    next if ( $? != 0 );
583✔
73

74
    next if ( !is_file( $output[0] ) );
569✔
75

76
    $cache->set( $cache_key_name, $output[0] );
569✔
77

78
    return $output[0];
569✔
79
  }
80

81
  return undef;
13✔
82
}
83

84
sub direct_exec {
85
  my ( $self, $exec, $option ) = @_;
6✔
86

87
  Rex::Commands::profiler()->start("direct_exec: $exec");
6✔
88

89
  my $class_name = ref $self;
6✔
90

91
  Rex::Logger::debug("$class_name/executing: $exec");
6✔
92
  my ( $out, $err ) = $self->_exec( $exec, $option );
6✔
93

94
  Rex::Commands::profiler()->end("direct_exec: $exec");
×
95

96
  Rex::Logger::debug($out) if ($out);
×
97
  if ($err) {
×
98
    Rex::Logger::debug("========= ERR ============");
×
99
    Rex::Logger::debug($err);
×
100
    Rex::Logger::debug("========= ERR ============");
×
101
  }
102

103
  if (wantarray) { return ( $out, $err ); }
×
104

105
  return $out;
×
106
}
107

108
sub _exec {
109
  my ($self) = @_;
×
110
  my $class_name = ref $self;
×
111
  die("_exec method must be overwritten by class ($class_name).");
×
112
}
113

114
sub shell {
115
  my ($self) = @_;
14✔
116

117
  Rex::Logger::debug("Detecting shell...");
14✔
118

119
  my $cache = Rex::get_cache();
14✔
120
  if ( $cache->valid("shell") ) {
14✔
121
    Rex::Logger::debug( "Found shell in cache: " . $cache->get("shell") );
×
122
    return Rex::Interface::Shell->create( $cache->get("shell") );
×
123
  }
124

125
  my %shells = Rex::Interface::Shell->get_shell_provider;
14✔
126
  for my $shell ( keys %shells ) {
14✔
127
    Rex::Logger::debug( "Searching for shell: " . $shell );
60✔
128
    $shells{$shell}->require;
60✔
129
    if ( $shells{$shell}->detect($self) ) {
60✔
130
      Rex::Logger::debug( "Found shell and using: " . $shell );
14✔
131
      $cache->set( "shell", $shell );
14✔
132
      return Rex::Interface::Shell->create($shell);
14✔
133
    }
134
  }
135

136
  return Rex::Interface::Shell->create("sh");
×
137
}
138

139
1;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc