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