lib/Rex/Interface/Shell/Csh.pm

filter: Statementstmt 23.6% 13 / 55 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 6 totaltotal 16.5% 17 / 103 CC 15 SCAR 48.2
CC
15
Cov
16%
exec
210.0
new
6.0
path
2.0
CRAP 123.5
« lib/Rex/Commands/File.pm ↑ Summary lib/Rex/Hardware/Swap.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Interface::Shell::Csh;
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 3 ▶use Rex::Interface::Shell::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use base qw(Rex::Interface::Shell::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
16 0 my $class = shift;
17 0 ▶ my $proto = ref($class) || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
18 0 my $self = $proto->SUPER::new(@_);
19  
20 0 bless( $self, $class );
21  
22 0 return $self;
23 }
24  
25 0 ▶sub path {
Subroutine path: not called CC=1 SCAR=6.9
Pod undocumented
26 0 my ( $self, $path ) = @_;
27 0 $self->{path} = $path;
28 }
29  
30 0 ▶sub source_global_profile {
Subroutine source_global_profile: not called CC=1 SCAR=6.9
Pod undocumented
31 0 my ( $self, $parse ) = @_;
32 0 $self->{source_global_profile} = $parse;
33 }
34  
35 0 ▶sub source_profile {
Subroutine source_profile: not called CC=1 SCAR=6.9
Pod undocumented
36 0 my ( $self, $parse ) = @_;
37 0 $self->{source_profile} = $parse;
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 # sub set_env {
46 # my ( $self, $env ) = @_;
47 # my $cmd = undef;
48 #
49 # die("Error: env must be a hash")
50 # if ( ref $env ne "HASH" );
51 #
52 # while ( my ( $k, $v ) = each($env) ) {
53 # $cmd .= "setenv $k \"$v\"; ";
54 # $self->{env_raw} .= "$k $v";
55 # }
56 #
57 # $self->{env} = $cmd;
58 # }
59  
60 0 ▶sub exec {
Subroutine exec: not called CC=14 SCAR=53.5
Pod undocumented
61 0 my ( $self, $cmd, $option ) = @_;
62  
63 0 ▶ if ( exists $option->{path} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option->{"path"}) 0 0 0
64 0 $self->path( $option->{path} );
65 }
66  
67 # if ( exists $option->{env} ) {
68 # $self->set_env( $option->{env} );
69 # }
70  
71 0 my $complete_cmd = $cmd;
72  
73 # if we need to execute without an sh command,
74 # use the format_cmd key
75 0 ▶ if ( exists $option->{no_sh} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option->{"no_sh"}) 0 0 0
76 0 $complete_cmd = $option->{format_cmd};
77 }
78  
79 0 ▶ if ( exists $option->{cwd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option->{"cwd"}) 0 0 0
80 0 $complete_cmd = "cd $option->{cwd} && $complete_cmd";
81 }
82  
83 0 ▶ if ( $self->{path} && !exists $self->{__env__}->{PATH} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"path"} and not exists $self->{"__env__"}{"PATH"}) 0 0 0
Condition0%0/3
$self->{"path"} and not exists $self->{"__env__"}{"PATH"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"path"} and not exists $self->{"__env__"}{"PATH"}
$self->{"path"} not exists $self->{"__env__"}{"PATH"}
Truth table0%0/3
A and not(B)
A= $self->{"path"}B= not exists $self->{"__env__"}{"PATH"}
ABresult
0X0
100
111
84 0 $complete_cmd = "set PATH=$self->{path}; $complete_cmd ";
85 }
86  
87 0 ▶ if ( $self->{locale} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"locale"}) 0 0 0
88 0 $complete_cmd = "set LC_ALL=$self->{locale} ; $complete_cmd ";
89 }
90  
91 0 ▶ if ( $self->{source_profile} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"source_profile"}) 0 0 0
92  
93 # csh is using .login
94 0 $complete_cmd = "source ~/.login >& /dev/null ; $complete_cmd";
95 }
96  
97 0 ▶ if ( $self->{source_global_profile} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"source_global_profile"}) 0 0 0
98 0 $complete_cmd = "source /etc/profile >& /dev/null ; $complete_cmd";
99 }
100  
101 0 ▶ if ( exists $self->{__env__} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"__env__"}) 0 0 0
102 0 ▶ if ( ref $self->{__env__} eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'__env__'} eq 'HASH') { } 0 0 0
103 0 for my $key ( keys %{ $self->{__env__} } ) {
104 0 my $val = $self->{__env__}->{$key};
105 0 $val =~ s/"/"'"'"/gms;
106 0 $complete_cmd = " setenv $key \"$val\" ; $complete_cmd ";
107 }
108 }
109 else {
110 0 $complete_cmd = $self->{__env__} . " $complete_cmd ";
111 }
112 }
113  
114 # this is due to a strange behaviour with Net::SSH2 / libssh2
115 # it may occur when you run rex inside a kvm virtualized host connecting to another virtualized vm on the same hardware
116 0 ▶ if ( Rex::Config->get_sleep_hack ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Rex::Config"->get_sleep_hack) 0 0 0
117 0 $complete_cmd .= " ; set f=\$? ; sleep .00000001 ; exit \$f";
118 }
119  
120 # rewrite the command again
121 0 ▶ if ( exists $option->{format_cmd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option->{"format_cmd"}) 0 0 0
122 0 $complete_cmd =~ s/\{\{CMD\}\}/$cmd/;
123 }
124  
125 0 return $complete_cmd;
126 }
127  
128 3 1;
« lib/Rex/Commands/File.pm ↑ Summary lib/Rex/Hardware/Swap.pm »