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