File Coverage

blib/lib/App/RemoteCommand/Select.pm
Criterion Covered Total %
statement 11 41 26.8
branch 0 4 0.0
condition 0 3 0.0
subroutine 4 9 44.4
pod 0 5 0.0
total 15 62 24.1


line stmt bran cond sub pod time code
1             package App::RemoteCommand::Select;
2 1     1   12 use v5.16;
  1         4  
3 1     1   5 use warnings;
  1         2  
  1         25  
4              
5 1     1   490 use IO::Select;
  1         1693  
  1         45  
6 1     1   408 use App::RemoteCommand::LineBuffer;
  1         3  
  1         405  
7              
8             sub new {
9 0     0 0   my $class = shift;
10 0           bless { select => IO::Select->new, container => [] }, $class;
11             }
12              
13             sub add {
14 0     0 0   my ($self, %args) = @_;
15 0           my $pid = $args{pid};
16 0           my $fh = $args{fh};
17 0           my $host = $args{host};
18 0   0       my $buffer = $args{buffer} || App::RemoteCommand::LineBuffer->new;
19 0           push @{$self->{container}}, {
  0            
20             pid => $pid,
21             fh => $fh,
22             host => $host,
23             buffer => $buffer,
24             };
25 0           $self->{select}->add($fh);
26             }
27              
28             sub can_read {
29 0     0 0   my $self = shift;
30 0           my @fh = $self->{select}->can_read(@_);
31 0           my @ready;
32 0           for my $c (@{$self->{container}}) {
  0            
33 0 0         if (grep { $c->{fh} == $_ } @fh) {
  0            
34 0           push @ready, $c;
35             }
36             }
37 0           return @ready;
38             }
39              
40             sub count {
41 0     0 0   my $self = shift;
42 0           $self->{select}->count;
43             }
44              
45             sub remove {
46 0     0 0   my ($self, $kind, $value) = @_;
47 0           for my $i (0..$#{$self->{container}}) {
  0            
48 0 0         if ($self->{container}[$i]{$kind} eq $value) {
49 0           my $remove = splice @{$self->{container}}, $i, 1;
  0            
50 0           $self->{select}->remove($remove->{fh});
51 0           return $remove;
52             }
53             }
54 0           return;
55             }
56              
57             1;