… | |
… | |
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 | |
… | |
… | |
22 | =cut |
22 | =cut |
23 | |
23 | |
24 | package AnyEvent::Strict; |
24 | package AnyEvent::Strict; |
25 | |
25 | |
26 | use Carp qw(croak); |
26 | use Carp qw(croak); |
|
|
27 | use Fcntl (); |
27 | |
28 | |
28 | use AnyEvent (); |
29 | use AnyEvent (); BEGIN { AnyEvent::common_sense } |
|
|
30 | |
|
|
31 | our @ISA; |
29 | |
32 | |
30 | AnyEvent::post_detect { |
33 | AnyEvent::post_detect { |
31 | # assume the first ISA member is the implementation |
34 | # assume the first ISA member is the implementation |
32 | # # and link us in before it in the chain. |
35 | # # and link us in before it in the chain. |
33 | my $MODEL = shift @AnyEvent::ISA; |
36 | my $MODEL = shift @AnyEvent::ISA; |
… | |
… | |
41 | |
44 | |
42 | ref $arg{cb} |
45 | ref $arg{cb} |
43 | or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; |
46 | or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; |
44 | delete $arg{cb}; |
47 | delete $arg{cb}; |
45 | |
48 | |
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]$/ |
49 | $arg{poll} =~ /^[rw]$/ |
51 | or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; |
50 | or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; |
|
|
51 | |
|
|
52 | if (defined fileno $arg{fh} or ref $arg{fh} or $arg{fh} !~ /^\s*\d+\s*$/) { |
|
|
53 | defined fileno $arg{fh} |
|
|
54 | or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; |
|
|
55 | } else { |
|
|
56 | $arg{fh} = AnyEvent::_dupfh $arg{poll}, $arg{fh}; |
|
|
57 | } |
|
|
58 | |
|
|
59 | -f $arg{fh} |
|
|
60 | and croak "AnyEvent->io called with fh argument pointing to a file"; |
|
|
61 | |
52 | delete $arg{poll}; |
62 | delete $arg{poll}; |
|
|
63 | delete $arg{fh}; |
53 | |
64 | |
54 | croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg |
65 | croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg |
55 | if keys %arg; |
66 | if keys %arg; |
56 | |
67 | |
57 | $class->SUPER::io (@_) |
68 | $class->SUPER::io (@_) |
… | |
… | |
85 | |
96 | |
86 | ref $arg{cb} |
97 | ref $arg{cb} |
87 | or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; |
98 | or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; |
88 | delete $arg{cb}; |
99 | delete $arg{cb}; |
89 | |
100 | |
90 | eval "require POSIX; 0 < &POSIX::SIG$arg{signal}" |
101 | defined AnyEvent::Base::sig2num $arg{signal} |
91 | or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; |
102 | or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; |
92 | delete $arg{signal}; |
103 | delete $arg{signal}; |
93 | |
104 | |
94 | croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg |
105 | croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg |
95 | if keys %arg; |
106 | if keys %arg; |
… | |
… | |
100 | sub child { |
111 | sub child { |
101 | my $class = shift; |
112 | my $class = shift; |
102 | my %arg = @_; |
113 | my %arg = @_; |
103 | |
114 | |
104 | ref $arg{cb} |
115 | ref $arg{cb} |
105 | or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; |
116 | or croak "AnyEvent->child called with illegal cb argument '$arg{cb}'"; |
106 | delete $arg{cb}; |
117 | delete $arg{cb}; |
107 | |
118 | |
108 | $arg{pid} =~ /^-?\d+$/ |
119 | $arg{pid} =~ /^-?\d+$/ |
109 | or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'"; |
120 | or croak "AnyEvent->child called with malformed pid value '$arg{pid}'"; |
110 | delete $arg{pid}; |
121 | delete $arg{pid}; |
111 | |
122 | |
112 | croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg |
123 | croak "AnyEvent->child called with unsupported parameter(s) " . join ", ", keys %arg |
113 | if keys %arg; |
124 | if keys %arg; |
114 | |
125 | |
115 | $class->SUPER::child (@_) |
126 | $class->SUPER::child (@_) |
|
|
127 | } |
|
|
128 | |
|
|
129 | sub idle { |
|
|
130 | my $class = shift; |
|
|
131 | my %arg = @_; |
|
|
132 | |
|
|
133 | ref $arg{cb} |
|
|
134 | or croak "AnyEvent->idle called with illegal cb argument '$arg{cb}'"; |
|
|
135 | delete $arg{cb}; |
|
|
136 | |
|
|
137 | croak "AnyEvent->idle called with unsupported parameter(s) " . join ", ", keys %arg |
|
|
138 | if keys %arg; |
|
|
139 | |
|
|
140 | $class->SUPER::idle (@_) |
116 | } |
141 | } |
117 | |
142 | |
118 | sub condvar { |
143 | sub condvar { |
119 | my $class = shift; |
144 | my $class = shift; |
120 | my %arg = @_; |
145 | my %arg = @_; |