Tangence/Client/via/sshunix.pm

filter: Statementstmt 33.3% 9 / 27 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 1 totaltotal 24.0% 12 / 50 CC 6 SCAR 27.2
CC
6
Cov
23%
connect
30.0
__ANON__
6.0
__ANON__
2.0
CRAP 15.2
« Tangence/Client/via/sshexec.pm ↑ Summary Tangence/Client.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2010-2021 -- leonerd@leonerd.org.uk
5  
6 package Net::Async::Tangence::Client::via::sshunix 0.16;
7  
8 1 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # A tiny program we can run remotely to connect STDIN/STDOUT to a UNIX socket
12 # given as $ARGV[0]
13 1 ▶use constant _NC_MICRO => <<'EOPERL';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 use Socket qw( AF_UNIX SOCK_STREAM pack_sockaddr_un );
15 use IO::Handle;
16 socket(my $socket, AF_UNIX, SOCK_STREAM, 0) or die "socket(AF_UNIX): $!\n";
17 connect($socket, pack_sockaddr_un($ARGV[0])) or die "connect $ARGV[0]: $!\n";
18 my $fd = fileno($socket);
19 $socket->blocking(0); $socket->autoflush(1);
20 STDIN->blocking(0); STDOUT->autoflush(1);
21 my $rin = "";
22 vec($rin, 0, 1) = 1;
23 vec($rin, $fd, 1) = 1;
24 print "READY";
25 while(1) {
26 select(my $rout = $rin, undef, undef, undef);
27 if(vec($rout, 0, 1)) {
28 sysread STDIN, my $buffer, 8192 or last;
29 print $socket $buffer;
30 }
31 if(vec($rout, $fd, 1)) {
32 sysread $socket, my $buffer, 8192 or last;
33 print $buffer;
34 }
35 }
36 EOPERL
37  
38 sub connect
39 0 ▶{
Subroutine connect: not called CC=5 SCAR=34.0
Pod undocumented
40 0 my $client = shift;
41 0 my ( $uri, %args ) = @_;
42  
43 0 my $host = $uri->authority;
44 0 my $path = $uri->path;
45 # Path will start with a leading /; we need to trim that
46 0 $path =~ s{^/}{};
47  
48 0 my @sshargs;
49 0 ▶ push @sshargs, "-4" if $args{family} and $args{family} eq "inet4";
Branch: 1 branch
BranchTrueFalseTotal
if $args{"family"} and $args{"family"} eq "inet4" 0 0 0
Condition0%0/3
$args{"family"} and $args{"family"} eq "inet4"
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"family"} and $args{"family"} eq "inet4"
$args{"family"} $args{"family"} eq "inet4"
Truth table0%0/3
A and B
A= $args{"family"}B= $args{"family"} eq "inet4"
ABresult
0X0
100
111
50 0 ▶ push @sshargs, "-6" if $args{family} and $args{family} eq "inet6";
Branch: 1 branch
BranchTrueFalseTotal
if $args{"family"} and $args{"family"} eq "inet6" 0 0 0
Condition0%0/3
$args{"family"} and $args{"family"} eq "inet6"
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"family"} and $args{"family"} eq "inet6"
$args{"family"} $args{"family"} eq "inet6"
Truth table0%0/3
A and B
A= $args{"family"}B= $args{"family"} eq "inet6"
ABresult
0X0
100
111
51  
52 return $client->connect_exec(
53 # Tell the remote perl we're going to send it a program on STDIN
54 [ 'ssh', @sshargs, $host, 'perl', '-', $path ]
55 0 ▶ )->then( sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 0 $client->write( _NC_MICRO . "\n__END__\n" );
57 0 my $f = $client->new_future;
58  
59 0 ▶ $client->configure( on_read => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
60 0 my ( $self, $buffref, $eof ) = @_;
61 0 ▶ return 0 unless $$buffref =~ s/READY//;
Branch: 1 branch
BranchTrueFalseTotal
unless $$buffref =~ s/READY//u 0 0 0
62 0 $self->configure( on_read => undef );
63 0 $f->done;
64 0 return 0;
65 0 } );
66  
67 0 return $f;
68 0 });
69 }
70  
71 1 0x55AA;
« Tangence/Client/via/sshexec.pm ↑ Summary Tangence/Client.pm »