… | |
… | |
12 | This module implements AnyEvent's strict mode. |
12 | This module implements AnyEvent's strict mode. |
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 | |
|
|
18 | B<< Currently, only AnyEvent I<methods> are checked, the AE:: I<functions> are not |
|
|
19 | affected. >> |
17 | |
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 at any time. |
21 | |
24 | |
… | |
… | |
32 | AnyEvent::post_detect { |
35 | AnyEvent::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 | |
40 | sub io { |
43 | sub io { |
41 | my $class = shift; |
44 | my $class = shift; |
42 | my %arg = @_; |
45 | my %arg = @_; |
… | |
… | |
46 | delete $arg{cb}; |
49 | delete $arg{cb}; |
47 | |
50 | |
48 | $arg{poll} =~ /^[rw]$/ |
51 | $arg{poll} =~ /^[rw]$/ |
49 | or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; |
52 | or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; |
50 | |
53 | |
51 | 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 { |
52 | defined fileno $arg{fh} |
57 | defined eval { fileno $arg{fh} } |
53 | or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; |
58 | or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; |
54 | } else { |
|
|
55 | $arg{fh} = AnyEvent::_dupfh $arg{poll}, $arg{fh}; |
|
|
56 | } |
59 | } |
57 | |
60 | |
58 | -f $arg{fh} |
61 | -f $arg{fh} |
59 | 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"; |
60 | |
63 | |