lib/Rex/Interface/Shell/Base.pm

filter: Statementstmt 70.2% 26 / 37 Branchbran 50.0% 2 / 4 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 7 totaltotal 51.4% 36 / 70 CC 6 SCAR 15.1
CC
6
Cov
63%
detect
8.6
set_environment
2.0
set_inner_shell
2.0
CRAP 4.5
« lib/Rex/Inventory/Hal/Object/Volume.pm ↑ Summary lib/Rex/Fork/Manager.pm »
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
l!l&&r!l&&!r
0140
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
54 14 my @parts = split /::/, $shell_class;
55 14 ▶ my $last_part = lc( $parts[-1] || "" );
Condition50%1/2
$parts[-1] || ''
l!l
140
MC/DC0%0/1
$parts[-1] || ''
$parts[-1]
Truth table50%1/2
A
A= $parts[-1]
Aresult
11
00
56  
57 14 my ($shell_path) = $con->_exec("echo \$SHELL");
58 14 ▶ if ( !$shell_path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($shell_path) 0 14 14
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
BranchTrueFalseTotal
if ($shell_path and $shell_path =~ m[/\Q$last_part\E$]u) 0 14 14
Condition33%1/3
$shell_path and $shell_path =~ m[/\Q$last_part\E$]u
!ll&&!rl&&r
1400
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
ABresult
0X0
100
111
74 0 return 1;
75 }
76  
77 14 return 0;
78 }
79  
80 3 1;
« lib/Rex/Inventory/Hal/Object/Volume.pm ↑ Summary lib/Rex/Fork/Manager.pm »