| 1 | # | ||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Rex::Interface::Shell::Base; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 14 | 2 | my $self = {}; | |||||||||||||||||||||||||||
| 15 | 2 | $self->{path} = undef; | |||||||||||||||||||||||||||
| 16 | 2 | $self->{__inner_shell__} = undef; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | bless( $self, $class ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | return $self; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 25 | 2 | my $class_name = ref $self; | |||||||||||||||||||||||||||
| 26 | 2 | my @parts = split( /::/, $class_name ); | |||||||||||||||||||||||||||
| 27 | 2 | return lc( $parts[-1] ); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub set_environment { | ||||||||||||||||||||||||||
|
Subroutine
set_environment: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 0 | my ( $self, $env ) = @_; | |||||||||||||||||||||||||||
| 32 | 0 | $self->{__env__} = $env; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub set_inner_shell { | ||||||||||||||||||||||||||
|
Subroutine
set_inner_shell: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 0 | my ( $self, $use_inner_shell ) = @_; | |||||||||||||||||||||||||||
| 37 | 0 | $self->{__inner_shell__} = $use_inner_shell; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub set_locale { | ||||||||||||||||||||||||||
|
Subroutine
set_locale: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 0 | my ( $self, $locale ) = @_; | |||||||||||||||||||||||||||
| 42 | 0 | $self->{locale} = $locale; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub set_sudo_env { | ||||||||||||||||||||||||||
|
Subroutine
set_sudo_env: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 0 | my ( $self, $sudo_env ) = @_; | |||||||||||||||||||||||||||
| 47 | 0 | $self->{__sudo_env__} = $sudo_env; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 14 | ▶ | sub detect { | ||||||||||||||||||||||||||
|
Subroutine
detect: called CC=6 SCAR=21.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 14 | my ( $self, $con ) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 14 | ▶ | my $shell_class = ref $self || $self; # $self might be only the classname | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 54 | 14 | my @parts = split /::/, $shell_class; | |||||||||||||||||||||||||||
| 55 | 14 | ▶ | my $last_part = lc( $parts[-1] || "" ); | ||||||||||||||||||||||||||
|
Condition50%1/2
$parts[-1] || ''
MC/DC0%0/1
$parts[-1] || ''
$parts[-1]
Truth table50%1/2
A
A= $parts[-1]
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 14 | my ($shell_path) = $con->_exec("echo \$SHELL"); | |||||||||||||||||||||||||||
| 58 | 14 | ▶ | if ( !$shell_path ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # try it a second time | ||||||||||||||||||||||||||||
| 61 | # we need this sometimes because the tty allocation is too slow, or | ||||||||||||||||||||||||||||
| 62 | # doesn't work, or ??? | ||||||||||||||||||||||||||||
| 63 | # it seems that this happens only for the very first command with | ||||||||||||||||||||||||||||
| 64 | # Net::OpenSSH when using a tty. | ||||||||||||||||||||||||||||
| 65 | 0 | Rex::Logger::debug( | |||||||||||||||||||||||||||
| 66 | "Failed detecting shell in the first try. Trying again."); | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ($shell_path) = $con->_exec("echo \$SHELL"); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 14 | $shell_path =~ s/(\r?\n)//gms; # remove unnecessary newlines | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 14 | ▶ | if ( $shell_path && $shell_path =~ m/\/\Q$last_part\E$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$shell_path and $shell_path =~ m[/\Q$last_part\E$]u
MC/DC0%0/2
$shell_path and $shell_path =~ m[/\Q$last_part\E$]u
$shell_path
$shell_path =~ m[/\Q$last_part\E$]u
Truth table33%1/3
A and B
A= $shell_pathB= $shell_path =~ m[/\Q$last_part\E$]u
| |||||||||||||||||||||||||||||
| 74 | 0 | return 1; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 14 | return 0; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | 1; | |||||||||||||||||||||||||||