| 1 | 132 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | package Remote::Perl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 132 | ▶ | use autodie qw(open); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 132 | ▶ | use List::Util qw(min); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 132 | ▶ | use IO::Select; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 132 | ▶ | use Remote::Perl::Bootstrap qw(bootstrap_payload wait_for_ready); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 132 | ▶ | use Remote::Perl::ModuleServer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 132 | ▶ | use Remote::Perl::Protocol qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | PROTOCOL_VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | MSG_HELLO MSG_READY MSG_RUN MSG_DATA MSG_EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | MSG_CREDIT MSG_MOD_REQ MSG_MOD_MISSING MSG_RETURN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | MSG_SIGNAL MSG_SIGNAL_ACK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | MSG_ERROR MSG_BYE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | STREAM_CONTROL STREAM_STDIN STREAM_STDOUT STREAM_STDERR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | TMPFILE_NONE TMPFILE_AUTO TMPFILE_LINUX TMPFILE_PERL TMPFILE_NAMED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | FLAGS_WARNINGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | encode_message encode_hello encode_credit decode_return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | encode_run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 132 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 132 | ▶ | use Remote::Perl::Transport; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 132 | our $VERSION = '0.005'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # -- Tmpfile strategy mapping -------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 132 | my %_TMPFILE_FLAG = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | off => TMPFILE_NONE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 => TMPFILE_AUTO, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | auto => TMPFILE_AUTO, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | linux => TMPFILE_LINUX, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | perl => TMPFILE_PERL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | named => TMPFILE_NAMED, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1456 | ▶ | sub _tmpfile_flag($v) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tmpfile_flag: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1456 | ▶ | return TMPFILE_NONE unless $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | die "Unknown tmpfile strategy '$v'; valid values: auto, linux, perl, named\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 456 | ▶ | unless exists $_TMPFILE_FLAG{$v}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 456 | return $_TMPFILE_FLAG{$v}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # -- Constructor --------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1522 | ▶ | sub new($class, %args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | cmd => $args{cmd} // die("'cmd' is required\n"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | window => $args{window} // 65_536, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | serve => $args{serve} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | tmpfile => $args{tmpfile} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | data_warn => $args{data_warn} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | _mod_srv => ($args{serve} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ? Remote::Perl::ModuleServer->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | inc => $args{inc} // \@INC, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | serve_filter => $args{serve_filter}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1522 | ▶ | : undef), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%10/12
$args{"cmd"} // die("'cmd' is required\n")
$args{"window"} // 65536
$args{"serve"} // 0
$args{"tmpfile"} // 0
$args{"data_warn"} // 0
$args{"inc"} // \@INC
MC/DC0%0/1
$args{"cmd"} // die("'cmd' is required\n")
$args{"cmd"}
MC/DC100%1/1
$args{"window"} // 65536
$args{"window"}
MC/DC100%1/1
$args{"serve"} // 0
$args{"serve"}
MC/DC100%1/1
$args{"tmpfile"} // 0
$args{"tmpfile"}
MC/DC100%1/1
$args{"data_warn"} // 0
$args{"data_warn"}
MC/DC0%0/1
$args{"inc"} // \@INC
$args{"inc"}
Truth table50%1/2
A
A= $args{"cmd"}
Truth table100%2/2
A
A= $args{"window"}
Truth table100%2/2
A
A= $args{"serve"}
Truth table100%2/2
A
A= $args{"tmpfile"}
Truth table100%2/2
A
A= $args{"data_warn"}
Truth table50%1/2
A
A= $args{"inc"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # set by _connect: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | _t => undef, # Remote::Perl::Transport | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | _parser => undef, # Remote::Perl::Protocol::Parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | _done => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | _ready => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # reset before each run: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | _on_stdout => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | _on_stderr => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | _returned => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | _return_code => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | _return_msg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | _stdin_credits => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | _stdin_eof_sent => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | _no_stdin => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | _stdin_str => undef, # plain-string stdin buffer; undef = use fh or none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1522 | $self->_connect; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1422 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # -- Internal: connect and handshake ------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1522 | ▶ | sub _connect($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connect: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1522 | my $t = Remote::Perl::Transport->new(cmd => $self->{cmd}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1522 | $t->connect; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1423 | $self->{_t} = $t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1423 | $self->{_parser} = Remote::Perl::Protocol::Parser->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1423 | $t->write_bytes(bootstrap_payload(serve => $self->{serve})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # Scan for the readiness marker; any leftover bytes belong to the protocol. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1423 | my $leftover = wait_for_ready($t->out_fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1423 | ▶ | $self->{_parser}->feed($leftover) if length $leftover; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | $self->_send(MSG_HELLO, STREAM_CONTROL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1423 | encode_hello(PROTOCOL_VERSION, $self->{window})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1423 | ▶ | $self->_pump_until(sub { $self->{_ready} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1423 | ▶ | unless ($self->{_ready}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | my $err = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | while ($t->stderr_ready(0.25)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | my $chunk = $t->read_stderr(4096); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | last unless defined $chunk && length $chunk; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $chunk and length $chunk
MC/DC0%0/2
defined $chunk and length $chunk
defined $chunk
length $chunk
Truth table33%1/3
A and B
A= defined $chunkB= length $chunk
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | $err .= $chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | $err =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | ▶ | my $detail = length($err) ? ": $err" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | die "remperl: connection failed$detail\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # -- Internal: wire I/O -------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 7584 | ▶ | sub _send($self, $type, $stream, $body = '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_send: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 7584 | $self->{_t}->write_bytes(encode_message($type, $stream, $body)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # -- Internal: event loop ------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Drive the event loop until $pred->() returns true or the connection closes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # $stdin_fh: optional filehandle whose data is forwarded to STREAM_STDIN. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Plain-string stdin is handled via _stdin_str / _drain_stdin_str; $stdin_fh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # is always undef in that case (strings have no real fd for select). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 4301 | ▶ | sub _pump_until($self, $pred, $stdin_fh = undef) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pump_until: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 4301 | my $t = $self->{_t}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 4301 | my $out_fd = fileno($t->out_fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 4301 | ▶ | my $in_fd = defined($stdin_fh) ? (fileno($stdin_fh) // -1) : -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
fileno $stdin_fh // -1
MC/DC0%0/1
fileno $stdin_fh // -1
fileno $stdin_fh
Truth table50%1/2
A
A= fileno $stdin_fh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 4301 | ▶ | until ($pred->() || $self->{_done}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&$pred() or $self->{"_done"}
MC/DC100%2/2
&$pred() or $self->{"_done"}
&$pred()
$self->{"_done"}
Truth table100%3/3
A or B
A= &$pred()B= $self->{"_done"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 8480 | my $sel = IO::Select->new($t->out_fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 8480 | ▶ | if ($in_fd >= 0 && !$self->{_stdin_eof_sent} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$in_fd >= 0 and not $self->{"_stdin_eof_sent"} and $self->{"_stdin_credits"} > 0
$in_fd >= 0 and not $self->{"_stdin_eof_sent"}
MC/DC100%3/3
$in_fd >= 0 and not $self->{"_stdin_eof_sent"} and $self->{"_stdin_credits"} > 0
$in_fd >= 0
not $self->{"_stdin_eof_sent"}
$self->{"_stdin_credits"} > 0
Truth table100%4/4
A and not(B) and C
A= $in_fd >= 0B= not $self->{"_stdin_eof_sent"}C= $self->{"_stdin_credits"} > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | && $self->{_stdin_credits} > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 28 | $sel->add($stdin_fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 8480 | for my $fh ($sel->can_read(1)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 8481 | ▶ | if (fileno($fh) == $out_fd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 8453 | my $data = $t->read_bytes(65_536); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 8453 | ▶ | unless (defined $data) { $self->{_done} = 1; last } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 8452 | $self->_dispatch($_) for $self->{_parser}->feed($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | elsif (fileno($fh) == $in_fd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 28 | $self->_forward_stdin($stdin_fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 10469 | ▶ | sub _dispatch($self, $msg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dispatch: called CC=24 SCAR=32.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 10469 | my ($type, $stream, $body) = @{$msg}{qw(type stream body)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 10469 | ▶ | if ($type == MSG_READY) { $self->{_ready} = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | elsif ($type == MSG_DATA) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1513 | ▶ | if ($stream == STREAM_STDOUT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1219 | ▶ | $self->{_on_stdout}->($body) if $self->{_on_stdout}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1219 | $self->_send(MSG_CREDIT, STREAM_STDOUT, encode_credit(length($body))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | elsif ($stream == STREAM_STDERR) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 294 | ▶ | $self->{_on_stderr}->($body) if $self->{_on_stderr}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 294 | $self->_send(MSG_CREDIT, STREAM_STDERR, encode_credit(length($body))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | elsif ($type == MSG_EOF) { } # EOF on stdout/stderr; RETURN signals end-of-run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | elsif ($type == MSG_CREDIT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1721 | ▶ | if ($stream == STREAM_STDIN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1721 | ▶ | if ($self->{_no_stdin} && !$self->{_stdin_eof_sent}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"_no_stdin"} and not $self->{"_stdin_eof_sent"}
MC/DC50%1/2
$self->{"_no_stdin"} and not $self->{"_stdin_eof_sent"}
$self->{"_no_stdin"}
not $self->{"_stdin_eof_sent"}
Truth table66%2/3
A and not(B)
A= $self->{"_no_stdin"}B= not $self->{"_stdin_eof_sent"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1424 | $self->_send(MSG_EOF, STREAM_STDIN); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1424 | $self->{_stdin_eof_sent} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 297 | $self->{_stdin_credits} += unpack('N', $body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 297 | ▶ | $self->_drain_stdin_str if defined $self->{_stdin_str}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | elsif ($type == MSG_MOD_REQ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | die "remperl: serve => 1 but no ModuleServer configured\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 31 | ▶ | if $self->{serve} && !$self->{_mod_srv}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"serve"} and not $self->{"_mod_srv"}
MC/DC0%0/2
$self->{"serve"} and not $self->{"_mod_srv"}
$self->{"serve"}
not $self->{"_mod_srv"}
Truth table66%2/3
A and not(B)
A= $self->{"serve"}B= not $self->{"_mod_srv"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 31 | ▶ | my $source = ($self->{serve} && $self->{_mod_srv}) ? $self->{_mod_srv}->find($body) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"serve"} and $self->{"_mod_srv"}
MC/DC50%1/2
$self->{"serve"} and $self->{"_mod_srv"}
$self->{"serve"}
$self->{"_mod_srv"}
Truth table66%2/3
A and B
A= $self->{"serve"}B= $self->{"_mod_srv"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 31 | ▶ | if (defined $source) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 16 | my $chunk = 65_536; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 16 | ▶ | for (my $off = 0; $off < length($source); $off += $chunk) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 16 | $self->_send(MSG_DATA, $stream, substr($source, $off, $chunk)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 16 | $self->_send(MSG_EOF, $stream); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 15 | $self->_send(MSG_MOD_MISSING, $stream); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | elsif ($type == MSG_SIGNAL_ACK) { } # reserved for future unresponsive-remote detection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | elsif ($type == MSG_RETURN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1456 | ($self->{_return_code}, $self->{_return_msg}) = decode_return($body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1456 | $self->{_returned} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 10 | elsif ($type == MSG_ERROR) { die "remperl: remote error: $body\n" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1422 | elsif ($type == MSG_BYE) { $self->{_done} = 1 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 269 | ▶ | sub _drain_stdin_str($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_drain_stdin_str: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 269 | ▶ | while ($self->{_stdin_credits} > 0 && length($self->{_stdin_str})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"_stdin_credits"} > 0 and length $self->{"_stdin_str"}
MC/DC100%2/2
$self->{"_stdin_credits"} > 0 and length $self->{"_stdin_str"}
$self->{"_stdin_credits"} > 0
length $self->{"_stdin_str"}
Truth table100%3/3
A and B
A= $self->{"_stdin_credits"} > 0B= length $self->{"_stdin_str"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 260 | my $take = min(65_536, $self->{_stdin_credits}, length($self->{_stdin_str})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 260 | $self->_send(MSG_DATA, STREAM_STDIN, substr($self->{_stdin_str}, 0, $take, '')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 260 | $self->{_stdin_credits} -= $take; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 269 | ▶ | if (!length($self->{_stdin_str}) && !$self->{_stdin_eof_sent}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $self->{'_stdin_str'} || $self->{'_stdin_eof_sent'}
MC/DC100%2/2
length $self->{'_stdin_str'} || $self->{'_stdin_eof_sent'}
length $self->{'_stdin_str'}
$self->{'_stdin_eof_sent'}
Truth table100%3/3
A || B
A= length $self->{'_stdin_str'}B= $self->{'_stdin_eof_sent'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 9 | $self->_send(MSG_EOF, STREAM_STDIN); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 9 | $self->{_stdin_eof_sent} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 28 | ▶ | sub _forward_stdin($self, $stdin_fh) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_forward_stdin: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 28 | my $n = min(65_536, $self->{_stdin_credits}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 28 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 28 | my $bytes = sysread($stdin_fh, $data, $n); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 28 | ▶ | if (!defined $bytes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | die "sysread stdin: $!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | elsif ($bytes == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 23 | $self->_send(MSG_EOF, STREAM_STDIN); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 23 | $self->{_stdin_eof_sent} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 5 | $self->_send(MSG_DATA, STREAM_STDIN, $data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 5 | $self->{_stdin_credits} -= $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # -- Public API ---------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # Run Perl source code on the remote. Returns the exit code (integer). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # In list context also returns the error message (empty string on success). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # Options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # on_stdout => sub($chunk) { ... } called for each stdout DATA chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # on_stderr => sub($chunk) { ... } called for each stderr DATA chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # stdin => $fh_or_str filehandle or plain string to use as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # remote STDIN (omit or pass undef for none) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # args => \@args (optional) set remote @ARGV before running | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1456 | ▶ | sub run_code($self, $source, %opts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_code: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1456 | $self->{_on_stdout} = $opts{on_stdout}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 1456 | $self->{_on_stderr} = $opts{on_stderr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 1456 | $self->{_returned} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1456 | $self->{_return_code} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1456 | $self->{_return_msg} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1456 | $self->{_stdin_credits} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1456 | $self->{_stdin_eof_sent} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1456 | ▶ | my $tmpfile = exists $opts{tmpfile} ? $opts{tmpfile} : $self->{tmpfile}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1456 | ▶ | my $warnings = $opts{warnings} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{"warnings"} // 0
MC/DC100%1/1
$opts{"warnings"} // 0
$opts{"warnings"}
Truth table100%2/2
A
A= $opts{"warnings"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1456 | ▶ | my $flags = _tmpfile_flag($tmpfile) | ($warnings ? FLAGS_WARNINGS : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1456 | ▶ | if (!$flags && $self->{data_warn} && $source =~ /^__DATA__(?:\r?\n|$)/m) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $flags and $self->{"data_warn"} and $source =~ /^__DATA__(?:\r?\n|$)/mu
not $flags and $self->{"data_warn"}
MC/DC100%3/3
not $flags and $self->{"data_warn"} and $source =~ /^__DATA__(?:\r?\n|$)/mu
not $flags
$self->{"data_warn"}
$source =~ /^__DATA__(?:\r?\n|$)/mu
Truth table100%4/4
not(A) and B and C
A= not $flagsB= $self->{"data_warn"}C= $source =~ /^__DATA__(?:\r?\n|$)/mu
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 5 | warn "remperl: script contains __DATA__ but --tmpfile is not set;" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | . " use --tmpfile for __DATA__ support\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1456 | my $stdin = $opts{stdin}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1456 | my $stdin_fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1456 | ▶ | if (!defined $stdin) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1424 | $self->{_no_stdin} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1424 | $self->{_stdin_str} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | elsif (!ref($stdin)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # Plain string: buffer it; credits drive delivery in _dispatch. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 9 | $self->{_no_stdin} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 9 | $self->{_stdin_str} = $stdin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 23 | $self->{_no_stdin} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 23 | $self->{_stdin_str} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 23 | $stdin_fh = $stdin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1456 | ▶ | my @argv = $opts{args} ? @{$opts{args}} : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 1456 | $self->_send(MSG_RUN, STREAM_CONTROL, encode_run($flags, $source, @argv)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 1456 | ▶ | $self->_pump_until(sub { $self->{_returned} }, $stdin_fh); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | ? ($self->{_return_code}, $self->{_return_msg}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1446 | ▶ | : $self->{_return_code}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # Read a local file and run its contents as Perl source on the remote. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # Accepts the same options as run_code, including tmpfile. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 841 | ▶ | sub run_file($self, $path, %opts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 841 | open(my $fh, '<', $path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 841 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 841 | my $source = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 841 | return $self->run_code($source, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # Send BYE and wait for the remote to echo it back, then close the transport. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1422 | ▶ | sub disconnect($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1422 | ▶ | return if $self->{_done}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 1422 | eval { $self->_send(MSG_BYE, STREAM_CONTROL) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1422 | ▶ | $self->_pump_until(sub { $self->{_done} }) unless $self->{_done}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 1422 | $self->{_t}->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 4 | ▶ | sub pid($self) { $self->{_t}->pid } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pid: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # Send a signal to the remote script by name (e.g. 'INT', 'TERM'). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # The remote relay process delivers it to the executor and replies with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # MSG_SIGNAL_ACK, which can later be used to detect unresponsive remotes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | ▶ | sub send_signal($self, $signame) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_signal: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | $self->_send(MSG_SIGNAL, STREAM_CONTROL, $signame); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1400 | ▶ | sub DESTROY($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | eval { $self->disconnect } unless $self->{_done}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 132 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||