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.4 by root, Wed Jul 9 11:00:02 2008 UTC vs.
Revision 1.16 by root, Thu Jul 9 22:37:53 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 ();
33use AnyEvent::Util ();
34
35our @ISA;
9 36
10AnyEvent::post_detect { 37AnyEvent::post_detect {
11 # assume the first ISA member is the implementation 38 # assume the first ISA member is the implementation
12 # # and link us in before it in the chain. 39 # # and link us in before it in the chain.
13 my $MODEL = shift @AnyEvent::ISA; 40 my $MODEL = shift @AnyEvent::ISA;
21 48
22 ref $arg{cb} 49 ref $arg{cb}
23 or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; 50 or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'";
24 delete $arg{cb}; 51 delete $arg{cb};
25 52
26 fileno $arg{fh}
27 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'";
28 delete $arg{fh};
29
30 $arg{poll} =~ /^[rw]$/ 53 $arg{poll} =~ /^[rw]$/
31 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; 54 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'";
55
56 if (defined fileno $arg{fh} or ref $arg{fh} or $arg{fh} !~ /^\s*\d+\s*$/) {
57 defined fileno $arg{fh}
58 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'";
59 } else {
60 $arg{fh} = AnyEvent::_dupfh $arg{poll}, $arg{fh};
61 }
62
63 -f $arg{fh}
64 and croak "AnyEvent->io called with fh argument pointing to a file";
65
32 delete $arg{poll}; 66 delete $arg{poll};
67 delete $arg{fh};
33 68
34 croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg 69 croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg
35 if keys %arg; 70 if keys %arg;
36 71
37 $class->SUPER::io (@_) 72 $class->SUPER::io (@_)
65 100
66 ref $arg{cb} 101 ref $arg{cb}
67 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 102 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
68 delete $arg{cb}; 103 delete $arg{cb};
69 104
70 eval "require POSIX; 0 < &POSIX::SIG$arg{signal}" 105 defined AnyEvent::Util::sig2num $arg{signal}
71 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; 106 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'";
72 delete $arg{signal}; 107 delete $arg{signal};
73 108
74 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 109 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
75 if keys %arg; 110 if keys %arg;
80sub child { 115sub child {
81 my $class = shift; 116 my $class = shift;
82 my %arg = @_; 117 my %arg = @_;
83 118
84 ref $arg{cb} 119 ref $arg{cb}
85 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 120 or croak "AnyEvent->child called with illegal cb argument '$arg{cb}'";
86 delete $arg{cb}; 121 delete $arg{cb};
87 122
88 $arg{pid} =~ /^-?\d+$/ 123 $arg{pid} =~ /^-?\d+$/
89 or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'"; 124 or croak "AnyEvent->child called with malformed pid value '$arg{pid}'";
90 delete $arg{pid}; 125 delete $arg{pid};
91 126
92 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 127 croak "AnyEvent->child called with unsupported parameter(s) " . join ", ", keys %arg
93 if keys %arg; 128 if keys %arg;
94 129
95 $class->SUPER::child (@_) 130 $class->SUPER::child (@_)
131}
132
133sub idle {
134 my $class = shift;
135 my %arg = @_;
136
137 ref $arg{cb}
138 or croak "AnyEvent->idle called with illegal cb argument '$arg{cb}'";
139 delete $arg{cb};
140
141 croak "AnyEvent->idle called with unsupported parameter(s) " . join ", ", keys %arg
142 if keys %arg;
143
144 $class->SUPER::idle (@_)
96} 145}
97 146
98sub condvar { 147sub condvar {
99 my $class = shift; 148 my $class = shift;
100 my %arg = @_; 149 my %arg = @_;
125 and croak "AnyEvent->now wrongly called with paramaters"; 174 and croak "AnyEvent->now wrongly called with paramaters";
126 175
127 $class->SUPER::now (@_) 176 $class->SUPER::now (@_)
128} 177}
129 178
1301 1791;
180
181=head1 AUTHOR
182
183 Marc Lehmann <schmorp@schmorp.de>
184 http://home.schmorp.de/
185
186=cut
187

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines