--- AnyEvent/lib/AnyEvent/Strict.pm 2008/07/08 23:54:12 1.2 +++ AnyEvent/lib/AnyEvent/Strict.pm 2009/07/08 02:01:12 1.13 @@ -1,13 +1,41 @@ +=head1 NAME + +AnyEvent::Strict - force strict mode on for the whole process + +=head1 SYNOPSIS + + use AnyEvent::Strict; + # strict mode now switched on + +=head1 DESCRIPTION + +This module implements AnyEvent's strict mode. + +Loading it makes AnyEvent check all arguments to AnyEvent-methods, at the +expense of being slower (often the argument checking takes longer than the +actual function). + +Normally, you don't load this module yourself but instead use it +indirectly via the C environment variable (see +L). However, this module can be loaded at any time. + +=cut + package AnyEvent::Strict; -# supply checks for argument validity for many functions -# this is an internal module. although it could be loaded -# at any time, this is not really documented. +no warnings; # *sigh* +use strict qw(vars subs); use Carp qw(croak); +use Fcntl (); + use AnyEvent (); +our @ISA; + AnyEvent::post_detect { + # assume the first ISA member is the implementation + # # and link us in before it in the chain. my $MODEL = shift @AnyEvent::ISA; unshift @ISA, $MODEL; unshift @AnyEvent::ISA, AnyEvent::Strict:: @@ -21,13 +49,21 @@ 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}'"; + + if (defined fileno $arg{fh} or ref $arg{fh} or $arg{fh} !~ /^\s*\d+\s*$/) { + defined fileno $arg{fh} + or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; + } else { + $arg{fh} = AnyEvent::_dupfh $arg{poll}, $arg{fh}; + } + + -f $arg{fh} + and croak "AnyEvent->io called with fh argument pointing to a file"; + delete $arg{poll}; + delete $arg{fh}; croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg if keys %arg; @@ -65,7 +101,7 @@ or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; delete $arg{cb}; - eval "require POSIX; defined &POSIX::SIG$arg{signal}" + eval "require POSIX; 0 < &POSIX::SIG$arg{signal}" or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; delete $arg{signal}; @@ -80,19 +116,33 @@ my %arg = @_; ref $arg{cb} - or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; + or croak "AnyEvent->child called with illegal cb argument '$arg{cb}'"; delete $arg{cb}; $arg{pid} =~ /^-?\d+$/ - or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'"; + or croak "AnyEvent->child called with malformed pid value '$arg{pid}'"; delete $arg{pid}; - croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg + croak "AnyEvent->child called with unsupported parameter(s) " . join ", ", keys %arg if keys %arg; $class->SUPER::child (@_) } +sub idle { + my $class = shift; + my %arg = @_; + + ref $arg{cb} + or croak "AnyEvent->idle called with illegal cb argument '$arg{cb}'"; + delete $arg{cb}; + + croak "AnyEvent->idle called with unsupported parameter(s) " . join ", ", keys %arg + if keys %arg; + + $class->SUPER::idle (@_) +} + sub condvar { my $class = shift; my %arg = @_; @@ -125,4 +175,12 @@ $class->SUPER::now (@_) } -1 +1; + +=head1 AUTHOR + + Marc Lehmann + http://home.schmorp.de/ + +=cut +