File Coverage

lib/Rex/Interface/Connection/Base.pm
Criterion Covered Total %
statement 22 64 34.3
branch 1 8 12.5
condition 1 3 33.3
subroutine 8 26 30.7
pod 0 22 0.0
total 32 123 26.0


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Interface::Connection::Base;
6              
7 67     67   955 use v5.12.5;
  67         387  
8 67     67   497 use warnings;
  67         219  
  67         3758  
9              
10             our $VERSION = '1.14.3'; # VERSION
11              
12 67     67   655 use Rex::Interface::Fs;
  67         244  
  67         1496  
13 67     67   2644 use Rex::Interface::Exec;
  67         199  
  67         930  
14              
15             sub new {
16 106     106 0 340 my $that = shift;
17 106   33     615 my $proto = ref($that) || $that;
18 106         349 my $self = {@_};
19              
20 106         315 bless( $self, $proto );
21              
22 106         664 $self->{__sudo_options__} = [];
23              
24 106         446 return $self;
25             }
26              
27 0     0 0 0 sub error { die("Must be implemented by Interface Class"); }
28 0     0 0 0 sub connect { die("Must be implemented by Interface Class"); }
29 0     0 0 0 sub disconnect { die("Must be implemented by Interface Class"); }
30 0     0 0 0 sub get_connection_object { die("Must be implemented by Interface Class"); }
31 0     0 0 0 sub is_connected { die("Must be implemented by Interface Class"); }
32 0     0 0 0 sub is_authenticated { die("Must be implemented by Interface Class"); }
33 0     0 0 0 sub get_connection_type { die("Must be implemented by Interface Class") }
34       2 0   sub reconnect { }
35              
36             sub get_fs_connection_object {
37 0     0 0 0 my ($self) = @_;
38 0         0 return $self;
39             }
40              
41             sub get_fs {
42 0     0 0 0 my $fs = Rex::Interface::Fs->create;
43 0         0 return $fs;
44             }
45              
46             sub get_exec {
47 0     0 0 0 my $exec = Rex::Interface::Exec->create;
48 0         0 return $exec;
49             }
50              
51             sub server {
52 386     386 0 969 my ($self) = @_;
53 386         2368 return $self->{server};
54             }
55              
56             sub get_auth_user {
57 0     0 0 0 my ($self) = @_;
58              
59 0 0       0 if ( exists $self->{__auth_info__} ) {
60 0         0 return $self->{__auth_info__}->{user};
61             }
62              
63 0         0 return "";
64             }
65              
66             sub get_auth {
67 0     0 0 0 my ($self) = @_;
68              
69 0 0       0 if ( exists $self->{__auth_info__} ) {
70 0         0 return $self->{__auth_info__};
71             }
72             }
73              
74             sub push_sudo_options {
75 0     0 0 0 my ( $self, @option ) = @_;
76 0 0       0 if ( ref $option[0] eq "HASH" ) {
77 0         0 push @{ $self->{__sudo_options__} }, $option[0];
  0         0  
78             }
79             else {
80 0         0 push @{ $self->{__sudo_options__} }, {@option};
  0         0  
81             }
82             }
83              
84             sub get_current_sudo_options {
85 0     0 0 0 my ($self) = @_;
86 0         0 return $self->{__sudo_options__}->[-1];
87             }
88              
89             sub push_use_sudo {
90 0     0 0 0 my ( $self, $use ) = @_;
91 0         0 push @{ $self->{__use_sudo__} }, $use;
  0         0  
92             }
93              
94             sub get_current_use_sudo {
95 3719     3719 0 9857 my ($self) = @_;
96              
97 3719 50       8574 if ( $self->{is_sudo} ) {
98 0         0 return 1;
99             }
100 3719         16548 return $self->{__use_sudo__}->[-1];
101             }
102              
103             sub pop_sudo_options {
104 0     0 0   my ($self) = @_;
105 0           pop @{ $self->{__sudo_options__} };
  0            
106             }
107              
108             sub pop_use_sudo {
109 0     0 0   my ($self) = @_;
110 0           pop @{ $self->{__use_sudo__} };
  0            
111             }
112              
113             sub run_sudo_unmodified {
114 0     0 0   my ( $self, $code ) = @_;
115 0           $self->push_sudo_options( {} );
116 0           $code->();
117 0           $self->pop_sudo_options();
118             }
119              
120             1;