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.2 by root, Tue Jul 8 23:54:12 2008 UTC vs.
Revision 1.13 by root, Wed Jul 8 02:01:12 2009 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
3# supply checks for argument validity for many functions 26no warnings; # *sigh*
4# this is an internal module. although it could be loaded 27use strict qw(vars subs);
5# at any time, this is not really documented.
6 28
7use Carp qw(croak); 29use Carp qw(croak);
30use Fcntl ();
31
8use AnyEvent (); 32use AnyEvent ();
9 33
34our @ISA;
35
10AnyEvent::post_detect { 36AnyEvent::post_detect {
37 # assume the first ISA member is the implementation
38 # # and link us in before it in the chain.
11 my $MODEL = shift @AnyEvent::ISA; 39 my $MODEL = shift @AnyEvent::ISA;
12 unshift @ISA, $MODEL; 40 unshift @ISA, $MODEL;
13 unshift @AnyEvent::ISA, AnyEvent::Strict:: 41 unshift @AnyEvent::ISA, AnyEvent::Strict::
14}; 42};
15 43
19 47
20 ref $arg{cb} 48 ref $arg{cb}
21 or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; 49 or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'";
22 delete $arg{cb}; 50 delete $arg{cb};
23 51
24 fileno $arg{fh}
25 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'";
26 delete $arg{fh};
27
28 $arg{poll} =~ /^[rw]$/ 52 $arg{poll} =~ /^[rw]$/
29 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; 53 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'";
54
55 if (defined fileno $arg{fh} or ref $arg{fh} or $arg{fh} !~ /^\s*\d+\s*$/) {
56 defined fileno $arg{fh}
57 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'";
58 } else {
59 $arg{fh} = AnyEvent::_dupfh $arg{poll}, $arg{fh};
60 }
61
62 -f $arg{fh}
63 and croak "AnyEvent->io called with fh argument pointing to a file";
64
30 delete $arg{poll}; 65 delete $arg{poll};
66 delete $arg{fh};
31 67
32 croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg 68 croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg
33 if keys %arg; 69 if keys %arg;
34 70
35 $class->SUPER::io (@_) 71 $class->SUPER::io (@_)
63 99
64 ref $arg{cb} 100 ref $arg{cb}
65 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 101 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
66 delete $arg{cb}; 102 delete $arg{cb};
67 103
68 eval "require POSIX; defined &POSIX::SIG$arg{signal}" 104 eval "require POSIX; 0 < &POSIX::SIG$arg{signal}"
69 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; 105 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'";
70 delete $arg{signal}; 106 delete $arg{signal};
71 107
72 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 108 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
73 if keys %arg; 109 if keys %arg;
78sub child { 114sub child {
79 my $class = shift; 115 my $class = shift;
80 my %arg = @_; 116 my %arg = @_;
81 117
82 ref $arg{cb} 118 ref $arg{cb}
83 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 119 or croak "AnyEvent->child called with illegal cb argument '$arg{cb}'";
84 delete $arg{cb}; 120 delete $arg{cb};
85 121
86 $arg{pid} =~ /^-?\d+$/ 122 $arg{pid} =~ /^-?\d+$/
87 or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'"; 123 or croak "AnyEvent->child called with malformed pid value '$arg{pid}'";
88 delete $arg{pid}; 124 delete $arg{pid};
89 125
90 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 126 croak "AnyEvent->child called with unsupported parameter(s) " . join ", ", keys %arg
91 if keys %arg; 127 if keys %arg;
92 128
93 $class->SUPER::child (@_) 129 $class->SUPER::child (@_)
130}
131
132sub idle {
133 my $class = shift;
134 my %arg = @_;
135
136 ref $arg{cb}
137 or croak "AnyEvent->idle called with illegal cb argument '$arg{cb}'";
138 delete $arg{cb};
139
140 croak "AnyEvent->idle called with unsupported parameter(s) " . join ", ", keys %arg
141 if keys %arg;
142
143 $class->SUPER::idle (@_)
94} 144}
95 145
96sub condvar { 146sub condvar {
97 my $class = shift; 147 my $class = shift;
98 my %arg = @_; 148 my %arg = @_;
123 and croak "AnyEvent->now wrongly called with paramaters"; 173 and croak "AnyEvent->now wrongly called with paramaters";
124 174
125 $class->SUPER::now (@_) 175 $class->SUPER::now (@_)
126} 176}
127 177
1281 1781;
179
180=head1 AUTHOR
181
182 Marc Lehmann <schmorp@schmorp.de>
183 http://home.schmorp.de/
184
185=cut
186

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines