|
|
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). |
|
|
17 | |
|
|
18 | Normally, you don't load this module yourself but instead use it |
|
|
19 | indirectly via the C<PERL_ANYEVENT_STRICT> environment variable (see |
|
|
20 | L<AnyEvent>). However, this module can be loaded at any time. |
|
|
21 | |
|
|
22 | =cut |
|
|
23 | |
1 | package AnyEvent::Strict; |
24 | package AnyEvent::Strict; |
2 | |
25 | |
3 | # supply checks for argument validity for many functions |
26 | no warnings; # *sigh* |
4 | # this is an internal module. although it could be loaded |
|
|
5 | # at any time, this is not really documented. |
|
|
6 | |
27 | |
7 | use Carp qw(croak); |
28 | use Carp qw(croak); |
|
|
29 | |
8 | use AnyEvent (); |
30 | use AnyEvent (); |
9 | |
31 | |
10 | AnyEvent::post_detect { |
32 | AnyEvent::post_detect { |
11 | # assume the first ISA member is the implementation |
33 | # assume the first ISA member is the implementation |
12 | # # and link us in before it in the chain. |
34 | # # and link us in before it in the chain. |
… | |
… | |
21 | |
43 | |
22 | ref $arg{cb} |
44 | ref $arg{cb} |
23 | or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; |
45 | or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; |
24 | delete $arg{cb}; |
46 | delete $arg{cb}; |
25 | |
47 | |
26 | fileno $arg{fh} |
48 | defined fileno $arg{fh} |
27 | or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; |
49 | or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; |
|
|
50 | -f $arg{fh} |
|
|
51 | and croak "AnyEvent->io called with fh argument pointing to a file"; |
28 | delete $arg{fh}; |
52 | delete $arg{fh}; |
29 | |
53 | |
30 | $arg{poll} =~ /^[rw]$/ |
54 | $arg{poll} =~ /^[rw]$/ |
31 | or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; |
55 | or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; |
32 | delete $arg{poll}; |
56 | delete $arg{poll}; |
… | |
… | |
65 | |
89 | |
66 | ref $arg{cb} |
90 | ref $arg{cb} |
67 | or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; |
91 | or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; |
68 | delete $arg{cb}; |
92 | delete $arg{cb}; |
69 | |
93 | |
70 | eval "require POSIX; defined &POSIX::SIG$arg{signal}" |
94 | eval "require POSIX; 0 < &POSIX::SIG$arg{signal}" |
71 | or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; |
95 | or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; |
72 | delete $arg{signal}; |
96 | delete $arg{signal}; |
73 | |
97 | |
74 | croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg |
98 | croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg |
75 | if keys %arg; |
99 | if keys %arg; |
… | |
… | |
80 | sub child { |
104 | sub child { |
81 | my $class = shift; |
105 | my $class = shift; |
82 | my %arg = @_; |
106 | my %arg = @_; |
83 | |
107 | |
84 | ref $arg{cb} |
108 | ref $arg{cb} |
85 | or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; |
109 | or croak "AnyEvent->child called with illegal cb argument '$arg{cb}'"; |
86 | delete $arg{cb}; |
110 | delete $arg{cb}; |
87 | |
111 | |
88 | $arg{pid} =~ /^-?\d+$/ |
112 | $arg{pid} =~ /^-?\d+$/ |
89 | or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'"; |
113 | or croak "AnyEvent->child called with malformed pid value '$arg{pid}'"; |
90 | delete $arg{pid}; |
114 | delete $arg{pid}; |
91 | |
115 | |
92 | croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg |
116 | croak "AnyEvent->child called with unsupported parameter(s) " . join ", ", keys %arg |
93 | if keys %arg; |
117 | if keys %arg; |
94 | |
118 | |
95 | $class->SUPER::child (@_) |
119 | $class->SUPER::child (@_) |
96 | } |
120 | } |
97 | |
121 | |
… | |
… | |
125 | and croak "AnyEvent->now wrongly called with paramaters"; |
149 | and croak "AnyEvent->now wrongly called with paramaters"; |
126 | |
150 | |
127 | $class->SUPER::now (@_) |
151 | $class->SUPER::now (@_) |
128 | } |
152 | } |
129 | |
153 | |
130 | 1 |
154 | 1; |
|
|
155 | |
|
|
156 | =head1 AUTHOR |
|
|
157 | |
|
|
158 | Marc Lehmann <schmorp@schmorp.de> |
|
|
159 | http://home.schmorp.de/ |
|
|
160 | |
|
|
161 | =cut |
|
|
162 | |