ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Strict.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Strict.pm (file contents):
Revision 1.14 by root, Thu Jul 9 18:58:19 2009 UTC vs.
Revision 1.23 by root, Sun Nov 14 02:26:29 2010 UTC

13 13
14Loading it makes AnyEvent check all arguments to AnyEvent-methods, at the 14Loading it makes AnyEvent check all arguments to AnyEvent-methods, at the
15expense of being slower (often the argument checking takes longer than the 15expense of being slower (often the argument checking takes longer than the
16actual function). 16actual function).
17 17
18B<< Currently, only AnyEvent I<methods> are checked, the AE:: I<functions> are not
19affected. >>
20
18Normally, you don't load this module yourself but instead use it 21Normally, you don't load this module yourself but instead use it
19indirectly via the C<PERL_ANYEVENT_STRICT> environment variable (see 22indirectly via the C<PERL_ANYEVENT_STRICT> environment variable (see
20L<AnyEvent>). However, this module can be loaded at any time. 23L<AnyEvent>). However, this module can be loaded at any time.
21 24
22=cut 25=cut
23 26
24package AnyEvent::Strict; 27package AnyEvent::Strict;
25 28
26use common::sense; 29use Carp qw(croak);
27 30
28use Carp qw(croak); 31use AnyEvent (); BEGIN { AnyEvent::common_sense }
29use Fcntl ();
30
31use AnyEvent ();
32 32
33our @ISA; 33our @ISA;
34 34
35AnyEvent::post_detect { 35AnyEvent::post_detect {
36 # assume the first ISA member is the implementation 36 # assume the first ISA member is the implementation
37 # # and link us in before it in the chain. 37 # # and link us in before it in the chain.
38 my $MODEL = shift @AnyEvent::ISA; 38 my $MODEL = shift @AnyEvent::ISA;
39 unshift @ISA, $MODEL; 39 unshift @ISA, $MODEL;
40 unshift @AnyEvent::ISA, AnyEvent::Strict:: 40 unshift @AnyEvent::ISA, AnyEvent::Strict::;
41}; 41};
42 42
43sub io { 43sub io {
44 my $class = shift; 44 my $class = shift;
45 my %arg = @_; 45 my %arg = @_;
49 delete $arg{cb}; 49 delete $arg{cb};
50 50
51 $arg{poll} =~ /^[rw]$/ 51 $arg{poll} =~ /^[rw]$/
52 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; 52 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'";
53 53
54 if (defined fileno $arg{fh} or ref $arg{fh} or $arg{fh} !~ /^\s*\d+\s*$/) { 54 if ($arg{fh} =~ /^\s*\d+\s*$/) {
55 $arg{fh} = AnyEvent::_dupfh $arg{poll}, $arg{fh};
56 } else {
55 defined fileno $arg{fh} 57 defined eval { fileno $arg{fh} }
56 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; 58 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'";
57 } else {
58 $arg{fh} = AnyEvent::_dupfh $arg{poll}, $arg{fh};
59 } 59 }
60 60
61 -f $arg{fh} 61 -f $arg{fh}
62 and croak "AnyEvent->io called with fh argument pointing to a file"; 62 and croak "AnyEvent->io called with fh argument pointing to a file";
63 63
98 98
99 ref $arg{cb} 99 ref $arg{cb}
100 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 100 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
101 delete $arg{cb}; 101 delete $arg{cb};
102 102
103 eval "require POSIX; 0 < &POSIX::SIG$arg{signal}" 103 defined AnyEvent::Base::sig2num $arg{signal} and $arg{signal} == 0
104 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; 104 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'";
105 delete $arg{signal}; 105 delete $arg{signal};
106 106
107 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 107 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
108 if keys %arg; 108 if keys %arg;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines