… | |
… | |
303 | =back |
303 | =back |
304 | |
304 | |
305 | =head2 SIGNAL WATCHERS |
305 | =head2 SIGNAL WATCHERS |
306 | |
306 | |
307 | You can watch for signals using a signal watcher, C<signal> is the signal |
307 | You can watch for signals using a signal watcher, C<signal> is the signal |
308 | I<name> without any C<SIG> prefix, C<cb> is the Perl callback to |
308 | I<name> in uppercase and without any C<SIG> prefix, C<cb> is the Perl |
309 | be invoked whenever a signal occurs. |
309 | callback to be invoked whenever a signal occurs. |
310 | |
310 | |
311 | Although the callback might get passed parameters, their value and |
311 | Although the callback might get passed parameters, their value and |
312 | presence is undefined and you cannot rely on them. Portable AnyEvent |
312 | presence is undefined and you cannot rely on them. Portable AnyEvent |
313 | callbacks cannot use arguments passed to signal watcher callbacks. |
313 | callbacks cannot use arguments passed to signal watcher callbacks. |
314 | |
314 | |
… | |
… | |
938 | $MODEL |
938 | $MODEL |
939 | or die "No event module selected for AnyEvent and autodetect failed. Install any one of these modules: EV, Event or Glib."; |
939 | or die "No event module selected for AnyEvent and autodetect failed. Install any one of these modules: EV, Event or Glib."; |
940 | } |
940 | } |
941 | } |
941 | } |
942 | |
942 | |
943 | unshift @ISA, $MODEL; |
|
|
944 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
943 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
|
|
944 | |
|
|
945 | if ($ENV{PERL_ANYEVENT_STRICT}) { |
|
|
946 | unshift @AnyEvent::Base::Strict::ISA, $MODEL; |
|
|
947 | unshift @ISA, AnyEvent::Base::Strict:: |
|
|
948 | } else { |
|
|
949 | unshift @ISA, $MODEL; |
|
|
950 | } |
945 | |
951 | |
946 | (shift @post_detect)->() while @post_detect; |
952 | (shift @post_detect)->() while @post_detect; |
947 | } |
953 | } |
948 | |
954 | |
949 | $MODEL |
955 | $MODEL |
… | |
… | |
1115 | |
1121 | |
1116 | # undocumented/compatibility with pre-3.4 |
1122 | # undocumented/compatibility with pre-3.4 |
1117 | *broadcast = \&send; |
1123 | *broadcast = \&send; |
1118 | *wait = \&_wait; |
1124 | *wait = \&_wait; |
1119 | |
1125 | |
|
|
1126 | package AnyEvent::Base::Strict; |
|
|
1127 | |
|
|
1128 | use Carp qw(croak); |
|
|
1129 | |
|
|
1130 | # supply checks for argument validity for many functions |
|
|
1131 | |
|
|
1132 | sub io { |
|
|
1133 | my $class = shift; |
|
|
1134 | my %arg = @_; |
|
|
1135 | |
|
|
1136 | ref $arg{cb} |
|
|
1137 | or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; |
|
|
1138 | delete $arg{cb}; |
|
|
1139 | |
|
|
1140 | fileno $arg{fh} |
|
|
1141 | or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; |
|
|
1142 | delete $arg{fh}; |
|
|
1143 | |
|
|
1144 | $arg{poll} =~ /^[rw]$/ |
|
|
1145 | or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; |
|
|
1146 | delete $arg{poll}; |
|
|
1147 | |
|
|
1148 | croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg |
|
|
1149 | if keys %arg; |
|
|
1150 | |
|
|
1151 | $class->SUPER::io (@_) |
|
|
1152 | } |
|
|
1153 | |
|
|
1154 | sub timer { |
|
|
1155 | my $class = shift; |
|
|
1156 | my %arg = @_; |
|
|
1157 | |
|
|
1158 | ref $arg{cb} |
|
|
1159 | or croak "AnyEvent->timer called with illegal cb argument '$arg{cb}'"; |
|
|
1160 | delete $arg{cb}; |
|
|
1161 | |
|
|
1162 | exists $arg{after} |
|
|
1163 | or croak "AnyEvent->timer called without mandatory 'after' parameter"; |
|
|
1164 | delete $arg{after}; |
|
|
1165 | |
|
|
1166 | $arg{interval} > 0 || !$arg{interval} |
|
|
1167 | or croak "AnyEvent->timer called with illegal interval argument '$arg{interval}'"; |
|
|
1168 | delete $arg{interval}; |
|
|
1169 | |
|
|
1170 | croak "AnyEvent->timer called with unsupported parameter(s) " . join ", ", keys %arg |
|
|
1171 | if keys %arg; |
|
|
1172 | |
|
|
1173 | $class->SUPER::timer (@_) |
|
|
1174 | } |
|
|
1175 | |
|
|
1176 | sub signal { |
|
|
1177 | my $class = shift; |
|
|
1178 | my %arg = @_; |
|
|
1179 | |
|
|
1180 | ref $arg{cb} |
|
|
1181 | or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; |
|
|
1182 | delete $arg{cb}; |
|
|
1183 | |
|
|
1184 | eval "require POSIX; defined &POSIX::SIG$arg{signal}" |
|
|
1185 | or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; |
|
|
1186 | delete $arg{signal}; |
|
|
1187 | |
|
|
1188 | croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg |
|
|
1189 | if keys %arg; |
|
|
1190 | |
|
|
1191 | $class->SUPER::signal (@_) |
|
|
1192 | } |
|
|
1193 | |
|
|
1194 | sub child { |
|
|
1195 | my $class = shift; |
|
|
1196 | my %arg = @_; |
|
|
1197 | |
|
|
1198 | ref $arg{cb} |
|
|
1199 | or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; |
|
|
1200 | delete $arg{cb}; |
|
|
1201 | |
|
|
1202 | $arg{pid} =~ /^-?\d+$/ |
|
|
1203 | or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'"; |
|
|
1204 | delete $arg{pid}; |
|
|
1205 | |
|
|
1206 | croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg |
|
|
1207 | if keys %arg; |
|
|
1208 | |
|
|
1209 | $class->SUPER::child (@_) |
|
|
1210 | } |
|
|
1211 | |
|
|
1212 | sub condvar { |
|
|
1213 | my $class = shift; |
|
|
1214 | my %arg = @_; |
|
|
1215 | |
|
|
1216 | !exists $arg{cb} or ref $arg{cb} |
|
|
1217 | or croak "AnyEvent->condvar called with illegal cb argument '$arg{cb}'"; |
|
|
1218 | delete $arg{cb}; |
|
|
1219 | |
|
|
1220 | croak "AnyEvent->condvar called with unsupported parameter(s) " . join ", ", keys %arg |
|
|
1221 | if keys %arg; |
|
|
1222 | |
|
|
1223 | $class->SUPER::condvar (@_) |
|
|
1224 | } |
|
|
1225 | |
|
|
1226 | sub time { |
|
|
1227 | my $class = shift; |
|
|
1228 | |
|
|
1229 | @_ |
|
|
1230 | and croak "AnyEvent->time wrongly called with paramaters"; |
|
|
1231 | |
|
|
1232 | $class->SUPER::time (@_) |
|
|
1233 | } |
|
|
1234 | |
|
|
1235 | sub now { |
|
|
1236 | my $class = shift; |
|
|
1237 | |
|
|
1238 | @_ |
|
|
1239 | and croak "AnyEvent->now wrongly called with paramaters"; |
|
|
1240 | |
|
|
1241 | $class->SUPER::now (@_) |
|
|
1242 | } |
|
|
1243 | |
1120 | =head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE |
1244 | =head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE |
1121 | |
1245 | |
1122 | This is an advanced topic that you do not normally need to use AnyEvent in |
1246 | This is an advanced topic that you do not normally need to use AnyEvent in |
1123 | a module. This section is only of use to event loop authors who want to |
1247 | a module. This section is only of use to event loop authors who want to |
1124 | provide AnyEvent compatibility. |
1248 | provide AnyEvent compatibility. |
… | |
… | |
1176 | conditions, such as not being able to load the event model specified by |
1300 | conditions, such as not being able to load the event model specified by |
1177 | C<PERL_ANYEVENT_MODEL>. |
1301 | C<PERL_ANYEVENT_MODEL>. |
1178 | |
1302 | |
1179 | When set to C<2> or higher, cause AnyEvent to report to STDERR which event |
1303 | When set to C<2> or higher, cause AnyEvent to report to STDERR which event |
1180 | model it chooses. |
1304 | model it chooses. |
|
|
1305 | |
|
|
1306 | =item C<PERL_ANYEVENT_STRICT> |
|
|
1307 | |
|
|
1308 | AnyEvent does not do much argument checking by default, as thorough |
|
|
1309 | argument checking is very costly. Setting this variable to a true value |
|
|
1310 | will cause AnyEvent to thoroughly check the arguments passed to most |
|
|
1311 | method calls and croaks if it finds any problems. In other words, enables |
|
|
1312 | "strict" mode. Unlike C<use strict> it is definitely recommended ot keep |
|
|
1313 | it off in production. |
1181 | |
1314 | |
1182 | =item C<PERL_ANYEVENT_MODEL> |
1315 | =item C<PERL_ANYEVENT_MODEL> |
1183 | |
1316 | |
1184 | This can be used to specify the event model to be used by AnyEvent, before |
1317 | This can be used to specify the event model to be used by AnyEvent, before |
1185 | auto detection and -probing kicks in. It must be a string consisting |
1318 | auto detection and -probing kicks in. It must be a string consisting |
… | |
… | |
1682 | |
1815 | |
1683 | use AnyEvent; |
1816 | use AnyEvent; |
1684 | |
1817 | |
1685 | Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can |
1818 | Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can |
1686 | be used to probe what backend is used and gain other information (which is |
1819 | be used to probe what backend is used and gain other information (which is |
1687 | probably even less useful to an attacker than PERL_ANYEVENT_MODEL). |
1820 | probably even less useful to an attacker than PERL_ANYEVENT_MODEL), and |
|
|
1821 | $ENV{PERL_ANYEGENT_STRICT}. |
1688 | |
1822 | |
1689 | |
1823 | |
1690 | =head1 BUGS |
1824 | =head1 BUGS |
1691 | |
1825 | |
1692 | Perl 5.8 has numerous memleaks that sometimes hit this module and are hard |
1826 | Perl 5.8 has numerous memleaks that sometimes hit this module and are hard |