File Coverage

blib/lib/MHFS/FD/Reader.pm
Criterion Covered Total %
statement 20 38 52.6
branch 0 8 0.0
condition n/a
subroutine 7 11 63.6
pod 0 3 0.0
total 27 60 45.0


line stmt bran cond sub pod time code
1             package MHFS::FD::Reader v0.7.0;
2 1     1   19 use 5.014;
  1         4  
3 1     1   14 use strict; use warnings;
  1     1   1  
  1         24  
  1         4  
  1         2  
  1         64  
4 1     1   6 use feature 'say';
  1         1  
  1         164  
5 1     1   7 use Time::HiRes qw( usleep clock_gettime CLOCK_MONOTONIC);
  1         3  
  1         8  
6 1     1   112 use IO::Poll qw(POLLIN POLLOUT POLLHUP);
  1         2  
  1         76  
7 1     1   7 use Scalar::Util qw(looks_like_number weaken);
  1         9  
  1         564  
8             sub new {
9 0     0 0   my ($class, $process, $fd, $func) = @_;
10 0           my %self = ('time' => clock_gettime(CLOCK_MONOTONIC), 'process' => $process, 'fd' => $fd, 'onReadReady' => $func);
11 0           say "PID " . $self{'process'}{'pid'} . 'FD ' . $self{'fd'};
12 0           weaken($self{'process'});
13 0           return bless \%self, $class;
14             }
15              
16             sub onReadReady {
17 0     0 0   my ($self) = @_;
18 0           my $ret = $self->{'onReadReady'}($self->{'fd'});
19 0 0         if($ret == 0) {
20 0           $self->{'process'}->remove($self->{'fd'});
21 0           return 1;
22             }
23 0 0         if($ret == -1) {
24 0           return undef;
25             }
26 0 0         if($ret == 1) {
27 0           return 1;
28             }
29             }
30              
31       0 0   sub onHangUp {
32              
33             }
34              
35             sub DESTROY {
36 0     0     my $self = shift;
37 0 0         print "PID " . $self->{'process'}{'pid'} . ' ' if($self->{'process'});
38 0           print "FD " . $self->{'fd'};
39 0           say ' reader DESTROY called';
40             }
41              
42             1;