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.9 by root, Fri Mar 27 10:49:50 2009 UTC vs.
Revision 1.24 by root, Sun Nov 14 02:26:52 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 manually at any time.
21 24
22=cut 25=cut
23 26
24package AnyEvent::Strict; 27package AnyEvent::Strict;
25 28
26use Carp qw(croak); 29use Carp qw(croak);
27 30
28use AnyEvent (); 31use AnyEvent (); BEGIN { AnyEvent::common_sense }
32
33our @ISA;
29 34
30AnyEvent::post_detect { 35AnyEvent::post_detect {
31 # assume the first ISA member is the implementation 36 # assume the first ISA member is the implementation
32 # # and link us in before it in the chain. 37 # # and link us in before it in the chain.
33 my $MODEL = shift @AnyEvent::ISA; 38 my $MODEL = shift @AnyEvent::ISA;
34 unshift @ISA, $MODEL; 39 unshift @ISA, $MODEL;
35 unshift @AnyEvent::ISA, AnyEvent::Strict:: 40 unshift @AnyEvent::ISA, AnyEvent::Strict::;
36}; 41};
37 42
38sub io { 43sub io {
39 my $class = shift; 44 my $class = shift;
40 my %arg = @_; 45 my %arg = @_;
41 46
42 ref $arg{cb} 47 ref $arg{cb}
43 or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; 48 or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'";
44 delete $arg{cb}; 49 delete $arg{cb};
45 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 {
46 defined fileno $arg{fh} 57 defined eval { fileno $arg{fh} }
47 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
48 -f $arg{fh} 61 -f $arg{fh}
49 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};
50 delete $arg{fh}; 65 delete $arg{fh};
51
52 $arg{poll} =~ /^[rw]$/
53 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'";
54 delete $arg{poll};
55 66
56 croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg 67 croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg
57 if keys %arg; 68 if keys %arg;
58 69
59 $class->SUPER::io (@_) 70 $class->SUPER::io (@_)
87 98
88 ref $arg{cb} 99 ref $arg{cb}
89 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 100 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
90 delete $arg{cb}; 101 delete $arg{cb};
91 102
92 eval "require POSIX; 0 < &POSIX::SIG$arg{signal}" 103 defined AnyEvent::Base::sig2num $arg{signal} and $arg{signal} == 0
93 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; 104 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'";
94 delete $arg{signal}; 105 delete $arg{signal};
95 106
96 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 107 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
97 if keys %arg; 108 if keys %arg;
102sub child { 113sub child {
103 my $class = shift; 114 my $class = shift;
104 my %arg = @_; 115 my %arg = @_;
105 116
106 ref $arg{cb} 117 ref $arg{cb}
107 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 118 or croak "AnyEvent->child called with illegal cb argument '$arg{cb}'";
108 delete $arg{cb}; 119 delete $arg{cb};
109 120
110 $arg{pid} =~ /^-?\d+$/ 121 $arg{pid} =~ /^-?\d+$/
111 or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'"; 122 or croak "AnyEvent->child called with malformed pid value '$arg{pid}'";
112 delete $arg{pid}; 123 delete $arg{pid};
113 124
114 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 125 croak "AnyEvent->child called with unsupported parameter(s) " . join ", ", keys %arg
115 if keys %arg; 126 if keys %arg;
116 127
117 $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 (@_)
118} 143}
119 144
120sub condvar { 145sub condvar {
121 my $class = shift; 146 my $class = shift;
122 my %arg = @_; 147 my %arg = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines