blib/lib/IO/Select/Trap.pm

filter: Statementstmt 13.3% 14 / 105 Branchbran 0.0% 0 / 86 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 20.0% 4 / 20 Podpod 0.0% 0 / 9 totaltotal 7.0% 18 / 257 CC 53 SCAR 47.6
CC
53
Cov
7%
select
380.0
new
42.0
_update
30.0
CRAP 117.2
↑ Summary
1 package IO::Select::Trap;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use vars qw/$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $VERSION = '0.032';
9  
10 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod undocumented
11 0 my $pkg = shift;
12 0 ▶ my $opts = (ref $_[0] eq 'HASH') ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
13 my $self = bless {
14 ioselect => new IO::Select(),
15 handles => {},
16 traps => ($opts->{traps} or 'String|Scalar'),
17 0 ▶ debug => (exists $opts->{debug} ? $opts->{debug} : 1),
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'debug'} ? : 0 0 0
Condition0%0/5
$opts->{'traps'} || 'String|Scalar'
l!l
00
ref $pkg || $pkg
l!l&&r!l&&!r
000
MC/DC0%0/1
$opts->{'traps'} || 'String|Scalar'
$opts->{'traps'}
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg $pkg
Truth table0%0/2
A
A= $opts->{'traps'}
Aresult
11
00
Truth table0%0/3
A || B
A= ref $pkgB= $pkg
ABresult
1X1
011
000
18 }, (ref $pkg || $pkg);
19  
20 0 ▶ $self->add(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
21 0 $self;
22 }
23  
24 0 ▶sub _update {
Subroutine _update: not called CC=5 SCAR=34.0
25 0 my ($self) = shift;
26 0 my $add = shift eq 'add';
27  
28 0 my @pthru;
29 0 foreach my $h (@_) {
30 0 ▶ next unless defined $h;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h 0 0 0
31 0 ▶ unless ($self->_trapped($h)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_trapped($h)) 0 0 0
32 0 push @pthru, $h;
33 0 next;
34 }
35  
36 0 ▶ if ($add) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add) { } 0 0 0
37 0 $self->{handles}->{\*{$h}} = $h;
38 } else {
39 0 delete $_[0]->{handles}->{\*{$h}};
40 }
41 }
42 0 return \@pthru;
43 }
44  
45 0 ▶sub _trapped {
Subroutine _trapped: not called CC=2 SCAR=17.9
46 0 my ($self, $h) = @_;
47 0 ▶ if ((ref $h) =~ /$self->{traps}/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($h) =~ /$self->{'traps'}/i) { } 0 0 0
48 0 carp (ref $h)." is trapped.";
49 0 return 1;
50 } else {
51 0 carp (ref $h)." is NOT trapped.";
52 0 return 0;
53 }
54 }
55  
56 0 ▶sub _count {
Subroutine _count: not called CC=1 SCAR=6.9
57 0 my $self = shift;
58 0 return scalar keys %{$self->{handles}};
59 }
60  
61 0 ▶sub _can_read {
Subroutine _can_read: not called CC=5 SCAR=34.0
62 0 my $self = shift;
63 0 ▶ return unless $self->_count;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_count 0 0 0
64 0 my @result;
65 0 ▶ while (my ($k, $h) = each %{$self->{handles}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"handles"};}) 0 0 0
66 0 ▶ push @result, $h if (length ${$h->sref});
Branch: 1 branch
BranchTrueFalseTotal
if length ${$h->sref;} 0 0 0
67 }
68 0 ▶ return wantarray ? @result : \@result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
69 }
70  
71 0 ▶sub _can_write {
Subroutine _can_write: not called CC=5 SCAR=34.0
72 0 my $self = shift;
73 0 ▶ return unless $self->_count;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_count 0 0 0
74 0 my @result;
75 0 ▶ while (my ($k, $h) = each %{$self->{handles}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"handles"};}) 0 0 0
76 0 ▶ push @result, $h if ($h->opened);
Branch: 1 branch
BranchTrueFalseTotal
if $h->opened 0 0 0
77 }
78 0 ▶ return wantarray ? @result : \@result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
79 }
80  
81 0 ▶sub _has_exception {}
Subroutine _has_exception: not called CC=1 SCAR=0.0
82  
83 0 ▶sub add {
Subroutine add: not called CC=2 SCAR=17.9
Pod undocumented
84 0 my $self = shift;
85 0 my $pthru = $self->_update('add', @_);
86 0 ▶ $self->{ioselect}->add(@$pthru) if @$pthru;
Branch: 1 branch
BranchTrueFalseTotal
if @$pthru 0 0 0
87 }
88  
89 0 ▶sub remove {
Subroutine remove: not called CC=2 SCAR=17.9
Pod undocumented
90 0 my $self = shift;
91 0 my $pthru = $self->_update('remove', @_);
92 0 ▶ $self->{ioselect}->remove(@$pthru) if @$pthru;
Branch: 1 branch
BranchTrueFalseTotal
if @$pthru 0 0 0
93 }
94  
95 0 ▶sub select {
Subroutine select: not called CC=19 SCAR=59.4
Pod undocumented
96 0 ▶ shift if defined $_[0] && !ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and not ref $_[0] 0 0 0
Condition0%0/3
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and not ref $_[0]
defined $_[0] not ref $_[0]
Truth table0%0/3
A and not(B)
A= defined $_[0]B= not ref $_[0]
ABresult
0X0
100
111
97 0 my ($r, $w, $e, $t) = @_;
98 0 my (@RR, @WR, @ER);
99  
100 0 ▶ my $rready = defined $r ? $r->_can_read : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $r ? : 0 0 0
101 0 ▶ my $wready = defined $w ? $w->_can_write : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $w ? : 0 0 0
102 0 ▶ my $eready = defined $e ? $e->_has_exception : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $e ? : 0 0 0
103  
104 0 ▶ push @RR, @$rready if defined $rready;
Branch: 1 branch
BranchTrueFalseTotal
if defined $rready 0 0 0
105 0 ▶ push @WR, @$wready if defined $wready;
Branch: 1 branch
BranchTrueFalseTotal
if defined $wready 0 0 0
106 0 ▶ push @ER, @$eready if defined $eready;
Branch: 1 branch
BranchTrueFalseTotal
if defined $eready 0 0 0
107  
108 0 ▶ my ($ir) = defined $r ? $r->{ioselect} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $r ? : 0 0 0
109 0 ▶ my ($iw) = defined $w ? $w->{ioselect} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $w ? : 0 0 0
110 0 ▶ my ($ie) = defined $e ? $e->{ioselect} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $e ? : 0 0 0
111  
112 0 ▶ if (@RR || @WR || @ER) {
Branch: 1 branch
BranchTrueFalseTotal
if (@RR or @WR or @ER) 0 0 0
Condition0%0/6
@RR or @WR or @ER
l!l&&r!l&&!r
000
@RR or @WR
l!l&&r!l&&!r
000
MC/DC0%0/3
@RR or @WR or @ER
@RR @WR @ER
Truth table0%0/4
A or B or C
A= @RRB= @WRC= @ER
ABCresult
1XX1
01X1
0011
0000
113 0 ▶ $t = 0 unless (defined $t); # Force non-blocking select()
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 0 0
114 }
115  
116 0 ($rready, $wready, $eready) = IO::Select->select($ir, $iw, $ie, $t);
117 0 ▶ push @RR, @$rready if defined $rready;
Branch: 1 branch
BranchTrueFalseTotal
if defined $rready 0 0 0
118 0 ▶ push @WR, @$wready if defined $wready;
Branch: 1 branch
BranchTrueFalseTotal
if defined $wready 0 0 0
119 0 ▶ push @ER, @$eready if defined $eready;
Branch: 1 branch
BranchTrueFalseTotal
if defined $eready 0 0 0
120  
121  
122 0 return (\@RR, \@WR, \@ER);
123 }
124  
125 0 ▶sub exists {
Subroutine exists: not called CC=2 SCAR=17.9
Pod undocumented
126 0 ▶ return unless defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 0 0
127 0 exists $_[0]->{handles}->{\*{$_[1]}};
128 }
129  
130 0 ▶sub can_read {
Subroutine can_read: not called CC=5 SCAR=34.0
Pod undocumented
131 0 my ($self, $t) = @_;
132 0 my @hready = $self->_can_read();
133 0 ▶ $t = 0 if (! defined $t && @hready);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $t and @hready 0 0 0
Condition0%0/3
not defined $t and @hready
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $t and @hready
not defined $t @hready
Truth table0%0/3
not(A) and B
A= not defined $tB= @hready
ABresult
0X0
100
111
134 0 my @iready = $self->{ioselect}->can_read($t);
135 return
136 0 ▶ @iready ?
Branch: 2 branches
BranchTrueFalseTotal
@iready ? : 0 0 0
@hready ? : 0 0 0
137 @hready ? (@iready, @hready) : @iready
138 : @hready;
139 }
140  
141 0 ▶sub can_write {
Subroutine can_write: not called CC=5 SCAR=34.0
Pod undocumented
142 0 my ($self, $t) = @_;
143 0 my @hready = $self->_can_write();
144 0 ▶ $t = 0 if (! defined $t && @hready);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $t and @hready 0 0 0
Condition0%0/3
not defined $t and @hready
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $t and @hready
not defined $t @hready
Truth table0%0/3
not(A) and B
A= not defined $tB= @hready
ABresult
0X0
100
111
145 0 my @iready = $self->{ioselect}->can_write($t);
146 return
147 0 ▶ @iready ?
Branch: 2 branches
BranchTrueFalseTotal
@iready ? : 0 0 0
@hready ? : 0 0 0
148 @hready ? (@iready, @hready) : @iready
149 : @hready;
150 }
151  
152 0 ▶sub has_exception {
Subroutine has_exception: not called CC=5 SCAR=34.0
Pod undocumented
153 0 my ($self, $t) = @_;
154 0 my @hready = $self->_has_exception();
155 0 ▶ $t = 0 if (! defined $t && @hready);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $t and @hready 0 0 0
Condition0%0/3
not defined $t and @hready
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $t and @hready
not defined $t @hready
Truth table0%0/3
not(A) and B
A= not defined $tB= @hready
ABresult
0X0
100
111
156 0 my @iready = $self->{ioselect}->has_exception($t);
157 return
158 0 ▶ @iready ?
Branch: 2 branches
BranchTrueFalseTotal
@iready ? : 0 0 0
@hready ? : 0 0 0
159 @hready ? (@iready, @hready) : @iready
160 : @hready;
161 }
162  
163 0 ▶sub count {
Subroutine count: not called CC=1 SCAR=6.9
Pod undocumented
164 0 my $self = shift;
165 return $self->{ioselect}->count
166 0 + scalar keys %{$self->{handles}};
167 }
168  
169 0 ▶sub _debug {
Subroutine _debug: not called CC=2 SCAR=17.9
170 0 my $self = shift;
171 0 ▶ print STDERR "$self: ", @_ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
172 }
173  
174  
175 1 1;
176 __END__
↑ Summary