File Coverage

blib/lib/MHFS/FD/Writer.pm
Criterion Covered Total %
statement 20 36 55.5
branch 0 6 0.0
condition n/a
subroutine 7 11 63.6
pod 0 3 0.0
total 27 56 48.2


line stmt bran cond sub pod time code
1             package MHFS::FD::Writer v0.7.0;
2 1     1   20 use 5.014;
  1         3  
3 1     1   5 use strict; use warnings;
  1     1   2  
  1         41  
  1         5  
  1         2  
  1         53  
4 1     1   6 use feature 'say';
  1         2  
  1         142  
5 1     1   8 use Time::HiRes qw( usleep clock_gettime CLOCK_MONOTONIC);
  1         2  
  1         20  
6 1     1   110 use IO::Poll qw(POLLIN POLLOUT POLLHUP);
  1         1  
  1         113  
7 1     1   7 use Scalar::Util qw(looks_like_number weaken);
  1         3  
  1         625  
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, 'onWriteReady' => $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 onWriteReady {
17 0     0 0   my ($self) = @_;
18 0           my $ret = $self->{'onWriteReady'}($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           say "PID " . $self->{'process'}{'pid'} . " FD " . $self->{'fd'}.' writer DESTROY called';
38             }
39              
40             1;