… | |
… | |
3 | AnyEvent::Strict - force strict mode on for the whole process |
3 | AnyEvent::Strict - force strict mode on for the whole process |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use AnyEvent::Strict; |
7 | use AnyEvent::Strict; |
8 | # struct mode now switched on |
8 | # strict mode now switched on |
9 | |
9 | |
10 | =head1 DESCRIPTION |
10 | =head1 DESCRIPTION |
11 | |
11 | |
12 | This module implements AnyEvent's strict mode. |
12 | This module implements AnyEvent's strict mode. |
13 | |
13 | |
14 | Loading it makes AnyEvent check all arguments to AnyEvent-methods, at the |
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 |
15 | expense of being slower (often the argument checking takes longer than the |
16 | actual fucntion). |
16 | actual function). |
17 | |
17 | |
18 | Normally, you don't load this module yourself but instead use it |
18 | Normally, you don't load this module yourself but instead use it |
19 | indirectly via the C<PERL_ANYEVENT_STRICT> environment variable (see |
19 | indirectly via the C<PERL_ANYEVENT_STRICT> environment variable (see |
20 | L<AnyEvent>). However, this module can be loaded at any time. |
20 | L<AnyEvent>). However, this module can be loaded at any time. |
21 | |
21 | |
22 | =cut |
22 | =cut |
23 | |
23 | |
24 | package AnyEvent::Strict; |
24 | package AnyEvent::Strict; |
25 | |
25 | |
|
|
26 | use common::sense; |
|
|
27 | |
26 | use Carp qw(croak); |
28 | use Carp qw(croak); |
|
|
29 | use Fcntl (); |
27 | |
30 | |
28 | use AnyEvent (); |
31 | use AnyEvent (); |
|
|
32 | |
|
|
33 | our @ISA; |
29 | |
34 | |
30 | AnyEvent::post_detect { |
35 | AnyEvent::post_detect { |
31 | # assume the first ISA member is the implementation |
36 | # assume the first ISA member is the implementation |
32 | # # and link us in before it in the chain. |
37 | # # and link us in before it in the chain. |
33 | my $MODEL = shift @AnyEvent::ISA; |
38 | my $MODEL = shift @AnyEvent::ISA; |
… | |
… | |
41 | |
46 | |
42 | ref $arg{cb} |
47 | ref $arg{cb} |
43 | or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; |
48 | or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; |
44 | delete $arg{cb}; |
49 | delete $arg{cb}; |
45 | |
50 | |
46 | defined fileno $arg{fh} |
|
|
47 | or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; |
|
|
48 | delete $arg{fh}; |
|
|
49 | |
|
|
50 | $arg{poll} =~ /^[rw]$/ |
51 | $arg{poll} =~ /^[rw]$/ |
51 | or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; |
52 | or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; |
|
|
53 | |
|
|
54 | if (defined fileno $arg{fh} or ref $arg{fh} or $arg{fh} !~ /^\s*\d+\s*$/) { |
|
|
55 | defined fileno $arg{fh} |
|
|
56 | or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; |
|
|
57 | } else { |
|
|
58 | $arg{fh} = AnyEvent::_dupfh $arg{poll}, $arg{fh}; |
|
|
59 | } |
|
|
60 | |
|
|
61 | -f $arg{fh} |
|
|
62 | and croak "AnyEvent->io called with fh argument pointing to a file"; |
|
|
63 | |
52 | delete $arg{poll}; |
64 | delete $arg{poll}; |
|
|
65 | delete $arg{fh}; |
53 | |
66 | |
54 | croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg |
67 | croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg |
55 | if keys %arg; |
68 | if keys %arg; |
56 | |
69 | |
57 | $class->SUPER::io (@_) |
70 | $class->SUPER::io (@_) |
… | |
… | |
100 | sub child { |
113 | sub child { |
101 | my $class = shift; |
114 | my $class = shift; |
102 | my %arg = @_; |
115 | my %arg = @_; |
103 | |
116 | |
104 | ref $arg{cb} |
117 | ref $arg{cb} |
105 | or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; |
118 | or croak "AnyEvent->child called with illegal cb argument '$arg{cb}'"; |
106 | delete $arg{cb}; |
119 | delete $arg{cb}; |
107 | |
120 | |
108 | $arg{pid} =~ /^-?\d+$/ |
121 | $arg{pid} =~ /^-?\d+$/ |
109 | or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'"; |
122 | or croak "AnyEvent->child called with malformed pid value '$arg{pid}'"; |
110 | delete $arg{pid}; |
123 | delete $arg{pid}; |
111 | |
124 | |
112 | croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg |
125 | croak "AnyEvent->child called with unsupported parameter(s) " . join ", ", keys %arg |
113 | if keys %arg; |
126 | if keys %arg; |
114 | |
127 | |
115 | $class->SUPER::child (@_) |
128 | $class->SUPER::child (@_) |
|
|
129 | } |
|
|
130 | |
|
|
131 | sub idle { |
|
|
132 | my $class = shift; |
|
|
133 | my %arg = @_; |
|
|
134 | |
|
|
135 | ref $arg{cb} |
|
|
136 | or croak "AnyEvent->idle called with illegal cb argument '$arg{cb}'"; |
|
|
137 | delete $arg{cb}; |
|
|
138 | |
|
|
139 | croak "AnyEvent->idle called with unsupported parameter(s) " . join ", ", keys %arg |
|
|
140 | if keys %arg; |
|
|
141 | |
|
|
142 | $class->SUPER::idle (@_) |
116 | } |
143 | } |
117 | |
144 | |
118 | sub condvar { |
145 | sub condvar { |
119 | my $class = shift; |
146 | my $class = shift; |
120 | my %arg = @_; |
147 | my %arg = @_; |