--- AnyEvent/lib/AnyEvent.pm 2008/07/08 23:10:20 1.166 +++ AnyEvent/lib/AnyEvent.pm 2008/07/08 23:44:51 1.167 @@ -305,8 +305,8 @@ =head2 SIGNAL WATCHERS You can watch for signals using a signal watcher, C is the signal -I without any C prefix, C is the Perl callback to -be invoked whenever a signal occurs. +I in uppercase and without any C prefix, C is the Perl +callback to be invoked whenever a signal occurs. Although the callback might get passed parameters, their value and presence is undefined and you cannot rely on them. Portable AnyEvent @@ -940,9 +940,15 @@ } } - unshift @ISA, $MODEL; push @{"$MODEL\::ISA"}, "AnyEvent::Base"; + if ($ENV{PERL_ANYEVENT_STRICT}) { + unshift @AnyEvent::Base::Strict::ISA, $MODEL; + unshift @ISA, AnyEvent::Base::Strict:: + } else { + unshift @ISA, $MODEL; + } + (shift @post_detect)->() while @post_detect; } @@ -1117,6 +1123,124 @@ *broadcast = \&send; *wait = \&_wait; +package AnyEvent::Base::Strict; + +use Carp qw(croak); + +# supply checks for argument validity for many functions + +sub io { + my $class = shift; + my %arg = @_; + + ref $arg{cb} + or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; + delete $arg{cb}; + + fileno $arg{fh} + or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; + delete $arg{fh}; + + $arg{poll} =~ /^[rw]$/ + or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; + delete $arg{poll}; + + croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg + if keys %arg; + + $class->SUPER::io (@_) +} + +sub timer { + my $class = shift; + my %arg = @_; + + ref $arg{cb} + or croak "AnyEvent->timer called with illegal cb argument '$arg{cb}'"; + delete $arg{cb}; + + exists $arg{after} + or croak "AnyEvent->timer called without mandatory 'after' parameter"; + delete $arg{after}; + + $arg{interval} > 0 || !$arg{interval} + or croak "AnyEvent->timer called with illegal interval argument '$arg{interval}'"; + delete $arg{interval}; + + croak "AnyEvent->timer called with unsupported parameter(s) " . join ", ", keys %arg + if keys %arg; + + $class->SUPER::timer (@_) +} + +sub signal { + my $class = shift; + my %arg = @_; + + ref $arg{cb} + or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; + delete $arg{cb}; + + eval "require POSIX; defined &POSIX::SIG$arg{signal}" + or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; + delete $arg{signal}; + + croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg + if keys %arg; + + $class->SUPER::signal (@_) +} + +sub child { + my $class = shift; + my %arg = @_; + + ref $arg{cb} + or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; + delete $arg{cb}; + + $arg{pid} =~ /^-?\d+$/ + or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'"; + delete $arg{pid}; + + croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg + if keys %arg; + + $class->SUPER::child (@_) +} + +sub condvar { + my $class = shift; + my %arg = @_; + + !exists $arg{cb} or ref $arg{cb} + or croak "AnyEvent->condvar called with illegal cb argument '$arg{cb}'"; + delete $arg{cb}; + + croak "AnyEvent->condvar called with unsupported parameter(s) " . join ", ", keys %arg + if keys %arg; + + $class->SUPER::condvar (@_) +} + +sub time { + my $class = shift; + + @_ + and croak "AnyEvent->time wrongly called with paramaters"; + + $class->SUPER::time (@_) +} + +sub now { + my $class = shift; + + @_ + and croak "AnyEvent->now wrongly called with paramaters"; + + $class->SUPER::now (@_) +} + =head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE This is an advanced topic that you do not normally need to use AnyEvent in @@ -1179,6 +1303,15 @@ When set to C<2> or higher, cause AnyEvent to report to STDERR which event model it chooses. +=item C + +AnyEvent does not do much argument checking by default, as thorough +argument checking is very costly. Setting this variable to a true value +will cause AnyEvent to thoroughly check the arguments passed to most +method calls and croaks if it finds any problems. In other words, enables +"strict" mode. Unlike C it is definitely recommended ot keep +it off in production. + =item C This can be used to specify the event model to be used by AnyEvent, before @@ -1684,7 +1817,8 @@ Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can be used to probe what backend is used and gain other information (which is -probably even less useful to an attacker than PERL_ANYEVENT_MODEL). +probably even less useful to an attacker than PERL_ANYEVENT_MODEL), and +$ENV{PERL_ANYEGENT_STRICT}. =head1 BUGS