Cinnamon/Remote.pm

filter: Statementstmt 50.0% 20 / 40 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 2 totaltotal 44.0% 26 / 59 CC 5 SCAR 25.8
CC
5
Cov
42%
execute
30.0
connection
2.0
BEGIN
1.0
CRAP 13.2
↑ Summary Cinnamon/CLI.pm »
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 || ''
l!l
00
MC/DC0%0/1
$self->host || ''
$self->host
Truth table0%0/2
A
A= $self->host
Aresult
11
00
24 0 my $conn = $self->connection;
25  
26 0 ▶ if ($opts->{sudo}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"sudo"}) 0 0 0
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
BranchTrueFalseTotal
() = $conn->open3({"tty", $opts->{"tty"}}, join(" ", @$commands)) or die 'open3 failed: ' . $conn->error 0 0 0
33  
34 0 ▶ if ($opts->{password}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"password"}) 0 0 0
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;
↑ Summary Cinnamon/CLI.pm »