blib/lib/IO/Poll.pm

filter: Statementstmt 85.7% 60 / 70 Branchbran 65.6% 21 / 32 Conditioncond 60.0% 3 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 9 / 9 Podpod 83.3% 5 / 6 totaltotal 80.0% 100 / 125 CC 20 SCAR 22.7
CC
20
Cov
79%
handles
26.3
poll
7.0
mask
7.0
CRAP 9.6
« blib/lib/IO/Socket/UNIX.pm ↑ Summary blib/lib/IO/Handle.pm »
1  
2 # IO::Poll.pm
3 #
4 # Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the same terms as Perl itself.
7  
8 package IO::Poll;
9  
10 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 our @ISA = qw(Exporter);
15 2 our $VERSION = "1.55";
16  
17 2 our @EXPORT = qw( POLLIN
18 POLLOUT
19 POLLERR
20 POLLHUP
21 POLLNVAL
22 );
23  
24 2 our @EXPORT_OK = qw(
25 POLLPRI
26 POLLRDNORM
27 POLLWRNORM
28 POLLRDBAND
29 POLLWRBAND
30 POLLNORM
31 );
32  
33 # [0] maps fd's to requested masks
34 # [1] maps fd's to returned masks
35 # [2] maps fd's to handles
36 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
37 2 my $class = shift;
38  
39 2 my $self = bless [{},{},{}], $class;
40  
41 2 $self;
42 }
43  
44 9 ▶sub mask {
Subroutine mask: called CC=7 SCAR=19.5
Pod documented
45 9 my $self = shift;
46 9 my $io = shift;
47 9 my $fd = fileno($io);
48 9 ▶ return unless defined $fd;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fd 0 9 9
49 9 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 3 9
50 6 my $mask = shift;
51 6 ▶ if($mask) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mask) { } 3 3 6
52 3 $self->[0]{$fd}{$io} = $mask; # the error events are always returned
53 3 $self->[1]{$fd} = 0; # output mask
54 3 $self->[2]{$io} = $io; # remember handle
55 } else {
56 3 delete $self->[0]{$fd}{$io};
57 3 ▶ unless(%{$self->[0]{$fd}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%{$self->[0]{$fd};}) 2 1 3
58 # We no longer have any handles for this FD
59 2 delete $self->[1]{$fd};
60 2 delete $self->[0]{$fd};
61 }
62 3 delete $self->[2]{$io};
63 }
64 }
65
66 9 ▶ return unless exists $self->[0]{$fd} and exists $self->[0]{$fd}{$io};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->[0]{$fd} and exists $self->[0]{$fd}{$io} 4 5 9
Condition100%3/3
exists $self->[0]{$fd} and exists $self->[0]{$fd}{$io}
!ll&&!rl&&r
225
MC/DC100%2/2
exists $self->[0]{$fd} and exists $self->[0]{$fd}{$io}
exists $self->[0]{$fd} exists $self->[0]{$fd}{$io}
Truth table100%3/3
A and B
A= exists $self->[0]{$fd}B= exists $self->[0]{$fd}{$io}
ABresult
0X0
100
111
67 5 return $self->[0]{$fd}{$io};
68 }
69  
70  
71 4 ▶sub poll {
Subroutine poll: called CC=7 SCAR=19.5
Pod documented
72 4 my($self,$timeout) = @_;
73  
74 4 $self->[1] = {};
75  
76 4 my($fd,$mask,$iom);
77 4 my @poll = ();
78  
79 4 ▶ while(($fd,$iom) = each %{$self->[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (($fd, $iom) = each %{$$self[0];}) 2 4 6
80 2 $mask = 0;
81 2 $mask |= $_ for values(%$iom);
82 2 push(@poll,$fd => $mask);
83 }
84  
85 4 ▶ my $ret = _poll(defined($timeout) ? $timeout * 1000 : -1,@poll);
Branch: 1 branch
BranchTrueFalseTotal
defined $timeout ? : 4 0 4
86  
87 4 ▶ return $ret
Branch: 1 branch
BranchTrueFalseTotal
unless $ret > 0 3 1 4
88 unless $ret > 0;
89  
90 1 ▶ while(@poll) {
Branch: 1 branch
BranchTrueFalseTotal
if (@poll) 1 1 2
91 1 my($fd,$got) = splice(@poll,0,2);
92 1 ▶ $self->[1]{$fd} = $got if $got;
Branch: 1 branch
BranchTrueFalseTotal
if $got 1 0 1
93 }
94  
95 1 return $ret;
96 }
97  
98 3 ▶sub events {
Subroutine events: called CC=3 SCAR=11.0
Pod documented
99 3 my $self = shift;
100 3 my $io = shift;
101 3 my $fd = fileno($io);
102 exists $self->[1]{$fd} and exists $self->[0]{$fd}{$io}
103 3 ▶ ? $self->[1]{$fd} & ($self->[0]{$fd}{$io}|POLLHUP|POLLERR|POLLNVAL)
Branch: 2 branches
BranchTrueFalseTotal
exists $self->[1]{$fd} and exists $self->[0]{$fd}{$io} ? $self->[1]{$fd} & ($self->[0]{$fd}{$io} | 16 | 8 | 32) : 0 2 1 3
exists $self->[0]{$fd}{$io} ? : 2 0 2
104 : 0;
105 }
106  
107 3 ▶sub remove {
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
108 3 my $self = shift;
109 3 my $io = shift;
110 3 $self->mask($io,0);
111 }
112  
113 3 ▶sub handles {
Subroutine handles: called CC=6 SCAR=32.7
Pod documented
114 3 my $self = shift;
115 3 ▶ return values %{$self->[2]} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 3 0 3
116  
117 0 ▶ my $events = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
118 0 my($fd,$ev,$io,$mask);
119 0 my @handles = ();
120  
121 0 ▶ while(($fd,$ev) = each %{$self->[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self[1];}) 0 0 0
122 0 ▶ while (($io,$mask) = each %{$self->[0]{$fd}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self[0]{$fd};}) 0 0 0
123 0 $mask |= POLLHUP|POLLERR|POLLNVAL; # must allow these
124 0 ▶ push @handles,$self->[2]{$io} if ($ev & $mask) & $events;
Branch: 1 branch
BranchTrueFalseTotal
if $ev & $mask & $events 0 0 0
125 }
126 }
127 0 return @handles;
128 }
129  
130 2 1;
131  
132 __END__
« blib/lib/IO/Socket/UNIX.pm ↑ Summary blib/lib/IO/Handle.pm »