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.11 by root, Tue Apr 14 04:27:32 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
26no warnings; # *sigh*
27
28use Carp qw(croak); 29use Carp qw(croak);
29 30
30use AnyEvent (); 31use AnyEvent (); BEGIN { AnyEvent::common_sense }
32
33our @ISA;
31 34
32AnyEvent::post_detect { 35AnyEvent::post_detect {
33 # assume the first ISA member is the implementation 36 # assume the first ISA member is the implementation
34 # # and link us in before it in the chain. 37 # # and link us in before it in the chain.
35 my $MODEL = shift @AnyEvent::ISA; 38 my $MODEL = shift @AnyEvent::ISA;
36 unshift @ISA, $MODEL; 39 unshift @ISA, $MODEL;
37 unshift @AnyEvent::ISA, AnyEvent::Strict:: 40 unshift @AnyEvent::ISA, AnyEvent::Strict::;
38}; 41};
39 42
40sub io { 43sub io {
41 my $class = shift; 44 my $class = shift;
42 my %arg = @_; 45 my %arg = @_;
43 46
44 ref $arg{cb} 47 ref $arg{cb}
45 or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; 48 or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'";
46 delete $arg{cb}; 49 delete $arg{cb};
47 50
51 $arg{poll} =~ /^[rw]$/
52 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'";
53
54 if ($arg{fh} =~ /^\s*\d+\s*$/) {
55 $arg{fh} = AnyEvent::_dupfh $arg{poll}, $arg{fh};
56 } else {
48 defined fileno $arg{fh} 57 defined eval { fileno $arg{fh} }
49 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; 58 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'";
59 }
60
50 -f $arg{fh} 61 -f $arg{fh}
51 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
64 delete $arg{poll};
52 delete $arg{fh}; 65 delete $arg{fh};
53
54 $arg{poll} =~ /^[rw]$/
55 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'";
56 delete $arg{poll};
57 66
58 croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg 67 croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg
59 if keys %arg; 68 if keys %arg;
60 69
61 $class->SUPER::io (@_) 70 $class->SUPER::io (@_)
89 98
90 ref $arg{cb} 99 ref $arg{cb}
91 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 100 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
92 delete $arg{cb}; 101 delete $arg{cb};
93 102
94 eval "require POSIX; 0 < &POSIX::SIG$arg{signal}" 103 defined AnyEvent::Base::sig2num $arg{signal} and $arg{signal} == 0
95 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; 104 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'";
96 delete $arg{signal}; 105 delete $arg{signal};
97 106
98 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 107 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
99 if keys %arg; 108 if keys %arg;
115 124
116 croak "AnyEvent->child called with unsupported parameter(s) " . join ", ", keys %arg 125 croak "AnyEvent->child called with unsupported parameter(s) " . join ", ", keys %arg
117 if keys %arg; 126 if keys %arg;
118 127
119 $class->SUPER::child (@_) 128 $class->SUPER::child (@_)
129}
130
131sub idle {
132 my $class = shift;
133 my %arg = @_;
134
135 ref $arg{cb}
136 or croak "AnyEvent->idle called with illegal cb argument '$arg{cb}'";
137 delete $arg{cb};
138
139 croak "AnyEvent->idle called with unsupported parameter(s) " . join ", ", keys %arg
140 if keys %arg;
141
142 $class->SUPER::idle (@_)
120} 143}
121 144
122sub condvar { 145sub condvar {
123 my $class = shift; 146 my $class = shift;
124 my %arg = @_; 147 my %arg = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines