blib/lib/AnyEvent/Strict.pm

filter: Statementstmt 31.7% 33 / 104 Branchbran 7.8% 5 / 64 Conditioncond 5.0% 1 / 20 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 40.0% 8 / 20 Podpod 0.0% 0 / 8 totaltotal 20.6% 47 / 228 CC 40 SCAR 37.0
CC
40
Cov
21%
__ANON__
132.0
io
56.0
signal
30.0
CRAP 40.4
« blib/lib/AnyEvent/Debug.pm ↑ Summary blib/lib/AnyEvent/Impl/UV.pm »
1 =head1 NAME
2  
3 AnyEvent::Strict - force strict mode on for the whole process
4  
5 =head1 SYNOPSIS
6  
7 use AnyEvent::Strict;
8 # strict mode now switched on
9  
10 =head1 DESCRIPTION
11  
12 This module implements AnyEvent's strict mode.
13  
14 Loading it makes AnyEvent check all arguments to AnyEvent-methods, at the
15 expense of being slower (often the argument checking takes longer than the
16 actual function). It also wraps all callbacks to check for modifications
17 of C<$_>, which indicates a programming bug inside the watcher callback.
18  
19 Normally, you don't load this module yourself but instead use it
20 indirectly via the C<PERL_ANYEVENT_STRICT> environment variable (see
21 L<AnyEvent>). However, this module can be loaded manually at any time.
22  
23 =cut
24  
25 package AnyEvent::Strict;
26  
27 1 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 $Carp::Internal{AE} = 1;
32 1 $Carp::Internal{AnyEvent::Strict} = 1;
33  
34 1 ▶use AnyEvent (); BEGIN { AnyEvent::common_sense }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 AnyEvent::_isa_hook 1 => "AnyEvent::Strict", 1;
37  
38 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=13.7
39 1 ▶ if (defined &Internals::SvREADONLY) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Internals::SvREADONLY) { } 1 0 1
40 # readonly available (at least 5.8.9+, working better in 5.10.1+)
41 1 ▶ *wrap = sub {
Subroutine __ANON__: called CC=1 SCAR=1.2
42 1 my $cb = shift;
43  
44 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 local $_;
46 0 Internals::SvREADONLY $_, 1;
47 0 &$cb;
48 }
49 1 };
50 } else {
51 # or not :/
52 0 my $magic = []; # a unique magic value
53  
54 0 ▶ *wrap = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 my $cb = shift;
56  
57 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
58 0 local $_ = $magic;
59  
60 0 &$cb;
61  
62 0 ▶ if (!ref $_ || $_ != $magic) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_ or $_ != $magic) 0 0 0
Condition0%0/3
not ref $_ or $_ != $magic
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $_ or $_ != $magic
not ref $_ $_ != $magic
Truth table0%0/3
not(A) or B
A= not ref $_B= $_ != $magic
ABresult
1X1
011
000
63 0 require AnyEvent::Debug;
64 0 die "callback $cb (" . AnyEvent::Debug::cb2str ($cb) . ") modified \$_ without restoring it.\n";
65 }
66 }
67 0 };
68 }
69 }
70  
71 1 our (@FD_INUSE, $FD_I);
72 0 ▶our $FD_CHECK_W = AE::timer 4, 4, sub {
Subroutine __ANON__: not called CC=11 SCAR=48.8
73 0 ▶ my $cnt = (@FD_INUSE < 100 * 10 ? int @FD_INUSE * 0.1 : 100) || 10;
Branch: 1 branch
BranchTrueFalseTotal
@AnyEvent::Strict::FD_INUSE < 1000 ? : 0 0 0
Condition0%0/2
(@AnyEvent::Strict::FD_INUSE < 1000 ? int @AnyEvent::Strict::FD_INUSE * 0.1 : 100) || 10
l!l
00
MC/DC0%0/1
(@AnyEvent::Strict::FD_INUSE < 1000 ? int @AnyEvent::Strict::FD_INUSE * 0.1 : 100) || 10
(@AnyEvent::Strict::FD_INUSE < 1000 ? int @AnyEvent::Strict::FD_INUSE * 0.1 : 100)
Truth table0%0/2
A
A= (@AnyEvent::Strict::FD_INUSE < 1000 ? int @AnyEvent::Strict::FD_INUSE * 0.1 : 100)
Aresult
11
00
74  
75 0 ▶ if ($FD_I <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($AnyEvent::Strict::FD_I <= 0) 0 0 0
76 #pop @FD_INUSE while @FD_INUSE && !$FD_INUSE[-1];
77 0 ▶ $FD_I = @FD_INUSE
Branch: 1 branch
BranchTrueFalseTotal
$AnyEvent::Strict::FD_I = @AnyEvent::Strict::FD_INUSE or return 0 0 0
78 or return; # empty
79 }
80  
81 0 ▶ $cnt = $FD_I if $cnt > $FD_I;
Branch: 1 branch
BranchTrueFalseTotal
if $cnt > $AnyEvent::Strict::FD_I 0 0 0
82  
83 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { do { not $AnyEvent::Strict::FD_INUSE[--$AnyEvent::Strict::FD_I] or POSIX::lseek($AnyEvent::Strict::FD_I, 0, 1) != -1 or $! != 9 or die } while --$cnt; 1 } } or &AE::log("crit", "File descriptor $AnyEvent::Strict::FD_I registered with AnyEvent but prematurely closed, event loop might malfunction.") 0 0 0
84 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
--$cnt and do { do { not $AnyEvent::Strict::FD_INUSE[--$AnyEvent::Strict::FD_I] or POSIX::lseek($AnyEvent::Strict::FD_I, 0, 1) != -1 or $! != 9 or die } } 0 0 0
85 0 ▶ !$FD_INUSE[--$FD_I]
Branch: 1 branch
BranchTrueFalseTotal
not $AnyEvent::Strict::FD_INUSE[--$AnyEvent::Strict::FD_I] or POSIX::lseek($AnyEvent::Strict::FD_I, 0, 1) != -1 or $! != 9 or die 0 0 0
Condition0%0/6
not $AnyEvent::Strict::FD_INUSE[--$AnyEvent::Strict::FD_I] or POSIX::lseek($AnyEvent::Strict::FD_I, 0, 1) != -1 or $! != 9
l!l&&r!l&&!r
000
not $AnyEvent::Strict::FD_INUSE[--$AnyEvent::Strict::FD_I] or POSIX::lseek($AnyEvent::Strict::FD_I, 0, 1) != -1
l!l&&r!l&&!r
000
MC/DC0%0/3
not $AnyEvent::Strict::FD_INUSE[--$AnyEvent::Strict::FD_I] or POSIX::lseek($AnyEvent::Strict::FD_I, 0, 1) != -1 or $! != 9
not $AnyEvent::Strict::FD_INUSE[--$AnyEvent::Strict::FD_I] POSIX::lseek($AnyEvent::Strict::FD_I, 0, 1) != -1 $! != 9
Truth table0%0/4
not(A) or B or C
A= not $AnyEvent::Strict::FD_INUSE[--$AnyEvent::Strict::FD_I]B= POSIX::lseek($AnyEvent::Strict::FD_I, 0, 1) != -1C= $! != 9
ABCresult
1XX1
01X1
0011
0000
86 or (POSIX::lseek $FD_I, 0, 1) != -1
87 or $! != Errno::EBADF
88 or die;
89 } while --$cnt;
90 0 1
91 } or AE::log crit => "File descriptor $FD_I registered with AnyEvent but prematurely closed, event loop might malfunction.";
92 1 };
93  
94 0 ▶sub io {
Subroutine io: not called CC=7 SCAR=40.3
Pod undocumented
95 0 my $class = shift;
96 0 my (%arg, $fh, $cb, $fd) = @_;
97  
98 ref $arg{cb}
99 0 ▶ or confess "AnyEvent->io called with illegal cb argument '$arg{cb}'";
Branch: 1 branch
BranchTrueFalseTotal
ref $arg{"cb"} or confess(qq[AnyEvent->io called with illegal cb argument '$arg{"cb"}']) 0 0 0
100 0 $cb = wrap delete $arg{cb};
101
102 0 ▶ $arg{poll} =~ /^[rw]$/
Branch: 1 branch
BranchTrueFalseTotal
$arg{"poll"} =~ /^[rw]$/ or confess(qq[AnyEvent->io called with illegal poll argument '$arg{"poll"}']) 0 0 0
103 or confess "AnyEvent->io called with illegal poll argument '$arg{poll}'";
104  
105 0 $fh = delete $arg{fh};
106  
107 0 ▶ if ($fh =~ /^\s*\d+\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh =~ /^\s*\d+\s*$/) { } 0 0 0
108 0 $fd = $fh;
109 0 ($fh) = AnyEvent::_dupfh $arg{poll}, $fh;
110 } else {
111 0 ▶ defined eval { $fd = fileno $fh }
Branch: 1 branch
BranchTrueFalseTotal
defined eval { do { $fd = fileno $fh } } or confess("AnyEvent->io called with illegal fh argument '${fh}'") 0 0 0
112 or confess "AnyEvent->io called with illegal fh argument '$fh'";
113 }
114  
115 0 ▶ -f $fh
Branch: 1 branch
BranchTrueFalseTotal
-f $fh and confess("AnyEvent->io called with fh argument pointing to a file") 0 0 0
116 and confess "AnyEvent->io called with fh argument pointing to a file";
117  
118 0 delete $arg{poll};
119
120 0 ▶ confess "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg
Branch: 1 branch
BranchTrueFalseTotal
if keys %arg 0 0 0
121 if keys %arg;
122  
123 0 ++$FD_INUSE[$fd];
124  
125 0 bless [
126 $fd,
127 $class->SUPER::io (@_, cb => $cb)
128 ], "AnyEvent::Strict::io";
129 }
130  
131 0 ▶sub AnyEvent::Strict::io::DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
132 0 --$FD_INUSE[$_[0][0]];
133 }
134  
135 1 ▶sub timer {
Subroutine timer: called CC=6 SCAR=19.2
Pod undocumented
136 1 my $class = shift;
137 1 my %arg = @_;
138  
139 ref $arg{cb}
140 1 ▶ or confess "AnyEvent->timer called with illegal cb argument '$arg{cb}'";
Branch: 1 branch
BranchTrueFalseTotal
ref $arg{"cb"} or confess(qq[AnyEvent->timer called with illegal cb argument '$arg{"cb"}']) 1 0 1
141 1 my $cb = wrap delete $arg{cb};
142
143 exists $arg{after}
144 1 ▶ or confess "AnyEvent->timer called without mandatory 'after' parameter";
Branch: 1 branch
BranchTrueFalseTotal
exists $arg{"after"} or confess("AnyEvent->timer called without mandatory 'after' parameter") 1 0 1
145 1 delete $arg{after};
146
147 1 ▶ !$arg{interval} or $arg{interval} > 0
Branch: 1 branch
BranchTrueFalseTotal
not $arg{"interval"} or $arg{"interval"} > 0 or confess(qq[AnyEvent->timer called with illegal interval argument '$arg{"interval"}']) 1 0 1
Condition33%1/3
not $arg{"interval"} or $arg{"interval"} > 0
l!l&&r!l&&!r
010
MC/DC0%0/2
not $arg{"interval"} or $arg{"interval"} > 0
not $arg{"interval"} $arg{"interval"} > 0
Truth table33%1/3
not(A) or B
A= not $arg{"interval"}B= $arg{"interval"} > 0
ABresult
1X1
011
000
148 or confess "AnyEvent->timer called with illegal interval argument '$arg{interval}'";
149 1 delete $arg{interval};
150
151 1 ▶ confess "AnyEvent->timer called with unsupported parameter(s) " . join ", ", keys %arg
Branch: 1 branch
BranchTrueFalseTotal
if keys %arg 0 1 1
152 if keys %arg;
153  
154 1 $class->SUPER::timer (@_, cb => $cb)
155 }
156  
157 0 ▶sub signal {
Subroutine signal: not called CC=5 SCAR=34.0
Pod undocumented
158 0 my $class = shift;
159 0 my %arg = @_;
160  
161 ref $arg{cb}
162 0 ▶ or confess "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
Branch: 1 branch
BranchTrueFalseTotal
ref $arg{"cb"} or confess(qq[AnyEvent->signal called with illegal cb argument '$arg{"cb"}']) 0 0 0
163 0 my $cb = wrap delete $arg{cb};
164
165 0 ▶ defined AnyEvent::Base::sig2num $arg{signal} and $arg{signal} == 0
Branch: 1 branch
BranchTrueFalseTotal
defined &AnyEvent::Base::sig2num($arg{"signal"}) and $arg{"signal"} == 0 or confess(qq[AnyEvent->signal called with illegal signal name '$arg{"signal"}']) 0 0 0
Condition0%0/3
defined &AnyEvent::Base::sig2num($arg{"signal"}) and $arg{"signal"} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined &AnyEvent::Base::sig2num($arg{"signal"}) and $arg{"signal"} == 0
defined &AnyEvent::Base::sig2num($arg{"signal"}) $arg{"signal"} == 0
Truth table0%0/3
A and B
A= defined &AnyEvent::Base::sig2num($arg{"signal"})B= $arg{"signal"} == 0
ABresult
0X0
100
111
166 or confess "AnyEvent->signal called with illegal signal name '$arg{signal}'";
167 0 delete $arg{signal};
168
169 0 ▶ confess "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
Branch: 1 branch
BranchTrueFalseTotal
if keys %arg 0 0 0
170 if keys %arg;
171  
172 0 $class->SUPER::signal (@_, cb => $cb)
173 }
174  
175 0 ▶sub child {
Subroutine child: not called CC=4 SCAR=30.0
Pod undocumented
176 0 my $class = shift;
177 0 my %arg = @_;
178  
179 ref $arg{cb}
180 0 ▶ or confess "AnyEvent->child called with illegal cb argument '$arg{cb}'";
Branch: 1 branch
BranchTrueFalseTotal
ref $arg{"cb"} or confess(qq[AnyEvent->child called with illegal cb argument '$arg{"cb"}']) 0 0 0
181 0 my $cb = wrap delete $arg{cb};
182
183 0 ▶ $arg{pid} =~ /^-?\d+$/
Branch: 1 branch
BranchTrueFalseTotal
$arg{"pid"} =~ /^-?\d+$/ or confess(qq[AnyEvent->child called with malformed pid value '$arg{"pid"}']) 0 0 0
184 or confess "AnyEvent->child called with malformed pid value '$arg{pid}'";
185 0 delete $arg{pid};
186
187 0 ▶ confess "AnyEvent->child called with unsupported parameter(s) " . join ", ", keys %arg
Branch: 1 branch
BranchTrueFalseTotal
if keys %arg 0 0 0
188 if keys %arg;
189  
190 0 $class->SUPER::child (@_, cb => $cb)
191 }
192  
193 0 ▶sub idle {
Subroutine idle: not called CC=3 SCAR=24.8
Pod undocumented
194 0 my $class = shift;
195 0 my %arg = @_;
196  
197 ref $arg{cb}
198 0 ▶ or confess "AnyEvent->idle called with illegal cb argument '$arg{cb}'";
Branch: 1 branch
BranchTrueFalseTotal
ref $arg{"cb"} or confess(qq[AnyEvent->idle called with illegal cb argument '$arg{"cb"}']) 0 0 0
199 0 my $cb = wrap delete $arg{cb};
200
201 0 ▶ confess "AnyEvent->idle called with unsupported parameter(s) " . join ", ", keys %arg
Branch: 1 branch
BranchTrueFalseTotal
if keys %arg 0 0 0
202 if keys %arg;
203  
204 0 $class->SUPER::idle (@_, cb => $cb)
205 }
206  
207 0 ▶sub condvar {
Subroutine condvar: not called CC=5 SCAR=34.0
Pod undocumented
208 0 my $class = shift;
209 0 my %arg = @_;
210  
211 !exists $arg{cb} or ref $arg{cb}
212 0 ▶ or confess "AnyEvent->condvar called with illegal cb argument '$arg{cb}'";
Branch: 1 branch
BranchTrueFalseTotal
not exists $arg{"cb"} or ref $arg{"cb"} or confess(qq[AnyEvent->condvar called with illegal cb argument '$arg{"cb"}']) 0 0 0
Condition0%0/3
not exists $arg{"cb"} or ref $arg{"cb"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $arg{"cb"} or ref $arg{"cb"}
not exists $arg{"cb"} ref $arg{"cb"}
Truth table0%0/3
not(A) or B
A= not exists $arg{"cb"}B= ref $arg{"cb"}
ABresult
1X1
011
000
213 0 ▶ my @cb = exists $arg{cb} ? (cb => wrap delete $arg{cb}) : ();
Branch: 1 branch
BranchTrueFalseTotal
exists $arg{'cb'} ? : 0 0 0
214
215 0 ▶ confess "AnyEvent->condvar called with unsupported parameter(s) " . join ", ", keys %arg
Branch: 1 branch
BranchTrueFalseTotal
if keys %arg 0 0 0
216 if keys %arg;
217  
218 0 $class->SUPER::condvar (@cb);
219 }
220  
221 0 ▶sub time {
Subroutine time: not called CC=2 SCAR=17.9
Pod undocumented
222 0 my $class = shift;
223  
224 @_
225 0 ▶ and confess "AnyEvent->time wrongly called with paramaters";
Branch: 1 branch
BranchTrueFalseTotal
@_ and confess("AnyEvent->time wrongly called with paramaters") 0 0 0
226  
227 0 $class->SUPER::time (@_)
228 }
229  
230 0 ▶sub now {
Subroutine now: not called CC=2 SCAR=17.9
Pod undocumented
231 0 my $class = shift;
232  
233 @_
234 0 ▶ and confess "AnyEvent->now wrongly called with paramaters";
Branch: 1 branch
BranchTrueFalseTotal
@_ and confess("AnyEvent->now wrongly called with paramaters") 0 0 0
235  
236 0 $class->SUPER::now (@_)
237 }
238  
239 =head1 AUTHOR
240  
241 Marc Lehmann <schmorp@schmorp.de>
242 http://anyevent.schmorp.de
243  
244 =cut
245  
246 1 1
247  
« blib/lib/AnyEvent/Debug.pm ↑ Summary blib/lib/AnyEvent/Impl/UV.pm »