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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines