Carapace/SSH.pm

filter: Statementstmt 35.0% 14 / 40 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 3 / 9 Podpod 0.0% 0 / 3 totaltotal 26.5% 17 / 64 CC 7 SCAR 22.1
CC
7
Cov
27%
run
20.0
_build_ssh
12.0
_stringify
6.0
CRAP 9.1
↑ Summary Carapace/Shell.pm »
1 package Shell::Carapace::SSH;
2 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use String::ShellQuote;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 has callback => (is => 'rw', required => 1);
8 1 has host => (is => 'rw', required => 1);
9 0 ▶has ssh_options => (is => 'rw', default => sub { {} });
Subroutine __ANON__: not called CC=1 SCAR=1.2
10 1 has ssh => (is => 'rw', lazy => 1, builder => 1, clearer => 1);
11  
12 0 ▶sub _build_ssh {
Subroutine _build_ssh: not called CC=3 SCAR=24.8
13 0 my $self = shift;
14 0 require Net::OpenSSH;
15 0 ▶ my %ssh_options = $self->ssh_options ? %{ $self->ssh_options } : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->ssh_options ? : 0 0 0
16 0 my $ssh = Net::OpenSSH->new($self->host, %ssh_options);
17 0 ▶ die $ssh->error if $ssh->error;
Branch: 1 branch
BranchTrueFalseTotal
if $ssh->error 0 0 0
18 0 return $ssh;
19 }
20  
21 # force ssh builder to run so the connection occurs during object instantiation
22 0 ▶sub BUILD { shift->ssh }
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
23  
24 0 ▶sub reconnect {
Subroutine reconnect: not called CC=1 SCAR=6.9
Pod undocumented
25 0 my $self = shift;
26 0 $self->clear_ssh;
27 0 $self->ssh;
28 }
29  
30 0 ▶sub run {
Subroutine run: not called CC=4 SCAR=30.0
Pod undocumented
31 0 my ($self, @cmd) = @_;
32  
33 0 $self->callback->('command', $self->_stringify(@cmd), $self->host);
34  
35 0 my ($pty, $pid) = $self->ssh->open2pty(@cmd);
36 0 ▶ die $self->ssh->error if $self->ssh->error;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ssh->error 0 0 0
37  
38 0 ▶ while (my $line = <$pty>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $pty)) 0 0 0
39 0 $line =~ s/([\r\n])$//g;
40 0 $self->callback->('remote-output', $line, $self->host);
41 }
42  
43 0 waitpid($pid, 0);
44  
45 0 ▶ if ($? != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
46 0 $self->callback->("error", $self->_stringify(@cmd), $self->host);
47 0 croak "cmd failed";
48 }
49 }
50  
51 0 ▶sub _stringify {
Subroutine _stringify: not called CC=2 SCAR=17.9
52 0 my ($self, @cmd) = @_;
53 0 ▶ return $cmd[0] if @cmd == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @cmd == 1 0 0 0
54 0 return join(" ", shell_quote @cmd);
55 }
56  
57 1 1;
↑ Summary Carapace/Shell.pm »