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.1 by root, Tue Jul 8 23:53:37 2008 UTC vs.
Revision 1.22 by root, Sun Nov 14 02:24:52 2010 UTC

1=head1 NAME
2
3AnyEvent::Strict - force strict mode on for the whole process
4
5=head1 SYNOPSIS
6
7 use AnyEvent::Strict;
8 # strict mode now switched on
9
10=head1 DESCRIPTION
11
12This module implements AnyEvent's strict mode.
13
14Loading it makes AnyEvent check all arguments to AnyEvent-methods, at the
15expense of being slower (often the argument checking takes longer than the
16actual function).
17
18Normally, you don't load this module yourself but instead use it
19indirectly via the C<PERL_ANYEVENT_STRICT> environment variable (see
20L<AnyEvent>). However, this module can be loaded at any time.
21
22=cut
23
1package AnyEvent::Strict; 24package AnyEvent::Strict;
2 25
3use Carp qw(croak); 26use Carp qw(croak);
4use AnyEvent (); 27
28use AnyEvent (); BEGIN { AnyEvent::common_sense }
29
30our @ISA;
5 31
6AnyEvent::post_detect { 32AnyEvent::post_detect {
33 # assume the first ISA member is the implementation
34 # # and link us in before it in the chain.
7 my $MODEL = shift @AnyEvent::ISA; 35 my $MODEL = shift @AnyEvent::ISA;
8 unshift @ISA, $MODEL; 36 unshift @ISA, $MODEL;
9 unshift @AnyEvent::ISA, AnyEvent::Strict:: 37 unshift @AnyEvent::ISA, AnyEvent::Strict::;
10}; 38};
11
12# supply checks for argument validity for many functions
13 39
14sub io { 40sub io {
15 my $class = shift; 41 my $class = shift;
16 my %arg = @_; 42 my %arg = @_;
17 43
18 ref $arg{cb} 44 ref $arg{cb}
19 or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; 45 or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'";
20 delete $arg{cb}; 46 delete $arg{cb};
21 47
22 fileno $arg{fh}
23 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'";
24 delete $arg{fh};
25
26 $arg{poll} =~ /^[rw]$/ 48 $arg{poll} =~ /^[rw]$/
27 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; 49 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'";
50
51 if ($arg{fh} =~ /^\s*\d+\s*$/) {
52 $arg{fh} = AnyEvent::_dupfh $arg{poll}, $arg{fh};
53 } else {
54 defined eval { fileno $arg{fh} }
55 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'";
56 }
57
58 -f $arg{fh}
59 and croak "AnyEvent->io called with fh argument pointing to a file";
60
28 delete $arg{poll}; 61 delete $arg{poll};
62 delete $arg{fh};
29 63
30 croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg 64 croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg
31 if keys %arg; 65 if keys %arg;
32 66
33 $class->SUPER::io (@_) 67 $class->SUPER::io (@_)
61 95
62 ref $arg{cb} 96 ref $arg{cb}
63 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 97 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
64 delete $arg{cb}; 98 delete $arg{cb};
65 99
66 eval "require POSIX; defined &POSIX::SIG$arg{signal}" 100 defined AnyEvent::Base::sig2num $arg{signal} and $arg{signal} == 0
67 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; 101 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'";
68 delete $arg{signal}; 102 delete $arg{signal};
69 103
70 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 104 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
71 if keys %arg; 105 if keys %arg;
76sub child { 110sub child {
77 my $class = shift; 111 my $class = shift;
78 my %arg = @_; 112 my %arg = @_;
79 113
80 ref $arg{cb} 114 ref $arg{cb}
81 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 115 or croak "AnyEvent->child called with illegal cb argument '$arg{cb}'";
82 delete $arg{cb}; 116 delete $arg{cb};
83 117
84 $arg{pid} =~ /^-?\d+$/ 118 $arg{pid} =~ /^-?\d+$/
85 or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'"; 119 or croak "AnyEvent->child called with malformed pid value '$arg{pid}'";
86 delete $arg{pid}; 120 delete $arg{pid};
87 121
88 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 122 croak "AnyEvent->child called with unsupported parameter(s) " . join ", ", keys %arg
89 if keys %arg; 123 if keys %arg;
90 124
91 $class->SUPER::child (@_) 125 $class->SUPER::child (@_)
126}
127
128sub idle {
129 my $class = shift;
130 my %arg = @_;
131
132 ref $arg{cb}
133 or croak "AnyEvent->idle called with illegal cb argument '$arg{cb}'";
134 delete $arg{cb};
135
136 croak "AnyEvent->idle called with unsupported parameter(s) " . join ", ", keys %arg
137 if keys %arg;
138
139 $class->SUPER::idle (@_)
92} 140}
93 141
94sub condvar { 142sub condvar {
95 my $class = shift; 143 my $class = shift;
96 my %arg = @_; 144 my %arg = @_;
121 and croak "AnyEvent->now wrongly called with paramaters"; 169 and croak "AnyEvent->now wrongly called with paramaters";
122 170
123 $class->SUPER::now (@_) 171 $class->SUPER::now (@_)
124} 172}
125 173
1261 1741;
175
176=head1 AUTHOR
177
178 Marc Lehmann <schmorp@schmorp.de>
179 http://home.schmorp.de/
180
181=cut
182

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines