|
|
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 | # struct 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 fucntion). |
|
|
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 | use Carp qw(croak); |
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); |
|
|
8 | use AnyEvent (); |
28 | use AnyEvent (); |
9 | |
29 | |
10 | AnyEvent::post_detect { |
30 | AnyEvent::post_detect { |
|
|
31 | # assume the first ISA member is the implementation |
|
|
32 | # # and link us in before it in the chain. |
11 | my $MODEL = shift @AnyEvent::ISA; |
33 | my $MODEL = shift @AnyEvent::ISA; |
12 | unshift @ISA, $MODEL; |
34 | unshift @ISA, $MODEL; |
13 | unshift @AnyEvent::ISA, AnyEvent::Strict:: |
35 | unshift @AnyEvent::ISA, AnyEvent::Strict:: |
14 | }; |
36 | }; |
15 | |
37 | |
… | |
… | |
19 | |
41 | |
20 | ref $arg{cb} |
42 | ref $arg{cb} |
21 | or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; |
43 | or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; |
22 | delete $arg{cb}; |
44 | delete $arg{cb}; |
23 | |
45 | |
24 | fileno $arg{fh} |
46 | defined fileno $arg{fh} |
25 | or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; |
47 | or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; |
26 | delete $arg{fh}; |
48 | delete $arg{fh}; |
27 | |
49 | |
28 | $arg{poll} =~ /^[rw]$/ |
50 | $arg{poll} =~ /^[rw]$/ |
29 | or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; |
51 | or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; |
… | |
… | |
63 | |
85 | |
64 | ref $arg{cb} |
86 | ref $arg{cb} |
65 | or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; |
87 | or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; |
66 | delete $arg{cb}; |
88 | delete $arg{cb}; |
67 | |
89 | |
68 | eval "require POSIX; defined &POSIX::SIG$arg{signal}" |
90 | eval "require POSIX; 0 < &POSIX::SIG$arg{signal}" |
69 | or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; |
91 | or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; |
70 | delete $arg{signal}; |
92 | delete $arg{signal}; |
71 | |
93 | |
72 | croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg |
94 | croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg |
73 | if keys %arg; |
95 | if keys %arg; |
… | |
… | |
123 | and croak "AnyEvent->now wrongly called with paramaters"; |
145 | and croak "AnyEvent->now wrongly called with paramaters"; |
124 | |
146 | |
125 | $class->SUPER::now (@_) |
147 | $class->SUPER::now (@_) |
126 | } |
148 | } |
127 | |
149 | |
128 | 1 |
150 | 1; |
|
|
151 | |
|
|
152 | =head1 AUTHOR |
|
|
153 | |
|
|
154 | Marc Lehmann <schmorp@schmorp.de> |
|
|
155 | http://home.schmorp.de/ |
|
|
156 | |
|
|
157 | =cut |
|
|
158 | |