| 1 | package Cinnamon::Remote; | ||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 2 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 2 | ▶ | use Net::OpenSSH; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 2 | ▶ | use Cinnamon::HandleManager; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 2 | ▶ | use Cinnamon::Logger; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 2 | has [qw(host user)] => (is => 'ro'); | |||||||||||
| 13 | |||||||||||||
| 14 | 0 | ▶ | sub connection { | ||||||||||
|
Subroutine
connection: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 15 | 0 | my $self = shift; | |||||||||||
| 16 | 0 | return Net::OpenSSH->new( | |||||||||||
| 17 | $self->host, user => $self->user, | ||||||||||||
| 18 | ); | ||||||||||||
| 19 | } | ||||||||||||
| 20 | |||||||||||||
| 21 | 0 | ▶ | sub execute { | ||||||||||
|
Subroutine
execute: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||
| 22 | 0 | my ($self, $commands, $opts) = @_; | |||||||||||
| 23 | 0 | ▶ | my $host = $self->host || ''; | ||||||||||
|
Condition0%0/2
$self->host || ''
MC/DC0%0/1
$self->host || ''
$self->host
Truth table0%0/2
A
A= $self->host
| |||||||||||||
| 24 | 0 | my $conn = $self->connection; | |||||||||||
| 25 | |||||||||||||
| 26 | 0 | ▶ | if ($opts->{sudo}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 0 | @$commands = ('sudo', '-Sk', @$commands); | |||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | my ($stdin, $stdout, $stderr, $pid) = $conn->open3({ | ||||||||||||
| 31 | tty => $opts->{tty}, | ||||||||||||
| 32 | 0 | ▶ | }, join ' ', @$commands) or die "open3 failed: " . $conn->error; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | |||||||||||||
| 34 | 0 | ▶ | if ($opts->{password}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 0 | print $stdin "$opts->{password}\n"; | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 0 | my $hm = Cinnamon::HandleManager->new(host => $self->host); | |||||||||||
| 39 | 0 | $hm->register_fh(stdout => $stdout); | |||||||||||
| 40 | 0 | $hm->register_fh(stderr => $stderr); | |||||||||||
| 41 | 0 | $hm->start_async_read(); | |||||||||||
| 42 | |||||||||||||
| 43 | 0 | my $stdout_str = $hm->captured_str('stdout'); | |||||||||||
| 44 | 0 | my $stderr_str = $hm->captured_str('stderr'); | |||||||||||
| 45 | |||||||||||||
| 46 | 0 | local $? = 0; | |||||||||||
| 47 | 0 | waitpid($pid, 0); | |||||||||||
| 48 | 0 | my $exitcode = $?; | |||||||||||
| 49 | |||||||||||||
| 50 | +{ | ||||||||||||
| 51 | 0 | stdout => $stdout_str, | |||||||||||
| 52 | stderr => $stderr_str, | ||||||||||||
| 53 | has_error => $exitcode > 0, | ||||||||||||
| 54 | error => $exitcode, | ||||||||||||
| 55 | }; | ||||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | 2 | !!1; | |||||||||||