| 1 | package Devel::REPL::Client::Select; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use IO::Select; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Term::ReadKey; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use constant { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | EOT => "\x04", | |||||||||||||||||||||||||||
| 12 | 1 | }; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | my $RESTORE_READMODE; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | END { | ||||||||||||||||||||||||||
|
Subroutine
END: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | ReadMode 0, \*STDIN if $RESTORE_READMODE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 0 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 22 | my $self = bless { | ||||||||||||||||||||||||||||
| 23 | port => $args{port}, | ||||||||||||||||||||||||||||
| 24 | path => $args{path}, | ||||||||||||||||||||||||||||
| 25 | mode => $args{mode}, | ||||||||||||||||||||||||||||
| 26 | 0 | socket => undef, | |||||||||||||||||||||||||||
| 27 | }, $class; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | return $self; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub listen { | ||||||||||||||||||||||||||
|
Subroutine
listen: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ($self->{port}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 36 | $self->{socket} = IO::Socket::INET->new( | ||||||||||||||||||||||||||||
| 37 | Listen => 1, | ||||||||||||||||||||||||||||
| 38 | LocalAddr => '127.0.0.1', | ||||||||||||||||||||||||||||
| 39 | LocalPort => $self->{port}, | ||||||||||||||||||||||||||||
| 40 | 0 | Proto => 'tcp', | |||||||||||||||||||||||||||
| 41 | ReuseAddr => 1, | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | } elsif ($self->{path}) { | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (-S $self->{path}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | unlink $self->{path} or die "Unable to unlink stale socket: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | $self->{socket} = IO::Socket::UNIX->new( | ||||||||||||||||||||||||||||
| 49 | Local => $self->{path}, | ||||||||||||||||||||||||||||
| 50 | 0 | ); | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($self->{socket} && defined $self->{mode}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"socket"} and defined $self->{"mode"}
MC/DC0%0/2
$self->{"socket"} and defined $self->{"mode"}
$self->{"socket"}
defined $self->{"mode"}
Truth table0%0/3
A and B
A= $self->{"socket"}B= defined $self->{"mode"}
| |||||||||||||||||||||||||||||
| 52 | chmod $self->{mode}, $self->{path} | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | or $self->{socket} = undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ($self->{socket}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | $self->{socket}->listen(1) | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | or $self->{socket} = undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | die "Unable to start listening: $!" unless $self->{socket}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub accept_and_process { | ||||||||||||||||||||||||||
|
Subroutine
accept_and_process: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 66 | 0 | my $client = $self->{socket}->accept; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | $RESTORE_READMODE = 1; | |||||||||||||||||||||||||||
| 69 | 0 | ReadMode 3, \*STDIN; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | my $fds = IO::Select->new; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | $fds->add($client, \*STDIN); | |||||||||||||||||||||||||||
| 74 | 0 | $client->blocking(0); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | for (;;) { | |||||||||||||||||||||||||||
| 77 | 0 | my ($rd, undef, $err) = IO::Select->select($fds, undef, $fds, 10); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ($err && @$err) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$err and @$err
MC/DC0%0/2
$err and @$err
$err
@$err
Truth table0%0/3
A and B
A= $errB= @$err
| |||||||||||||||||||||||||||||
| 80 | 0 | die "One of the handles became invalid"; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | for my $hnd (@$rd) { | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($hnd == $client) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | _from_to($client, \*STDOUT); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ($hnd == \*STDIN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | while (defined(my $key = ReadKey -1, \*STDIN)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | my $ok = do { | |||||||||||||||||||||||||||
| 90 | 0 | local $SIG{PIPE} = 'IGNORE'; | |||||||||||||||||||||||||||
| 91 | 0 | syswrite $client, $key; | |||||||||||||||||||||||||||
| 92 | }; | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | die "Error during write: $!" if !defined $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ($key eq EOT) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | syswrite *STDOUT, "^D\n"; | |||||||||||||||||||||||||||
| 96 | 0 | return; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub _from_to { | ||||||||||||||||||||||||||
|
Subroutine
_from_to: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 105 | 0 | my ($from, $to) = @_; | |||||||||||||||||||||||||||
| 106 | 0 | my $buff; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | my $count = sysread $from, $buff, 1000; | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | die "Error during read: $!" if !defined $count; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | my $written = syswrite $to, $buff, $count; | |||||||||||||||||||||||||||
| 111 | 0 | ▶ | die "Error during write: $!" if !defined $written || $written != $count; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $written or $written != $count
MC/DC0%0/2
not defined $written or $written != $count
not defined $written
$written != $count
Truth table0%0/3
not(A) or B
A= not defined $writtenB= $written != $count
| |||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub close { | ||||||||||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | $self->{socket}->close if $self->{socket}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | 1; | |||||||||||||||||||||||||||