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