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.10 by root, Wed Apr 1 14:02:27 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
26no warnings; # *sigh*
27
3use Carp qw(croak); 28use Carp qw(croak);
29
4use AnyEvent (); 30use AnyEvent ();
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} 48 defined fileno $arg{fh}
23 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'"; 49 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'";
50 -f $arg{fh}
51 and croak "AnyEvent->io called with fh argument pointing to a file";
24 delete $arg{fh}; 52 delete $arg{fh};
25 53
26 $arg{poll} =~ /^[rw]$/ 54 $arg{poll} =~ /^[rw]$/
27 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'"; 55 or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'";
28 delete $arg{poll}; 56 delete $arg{poll};
61 89
62 ref $arg{cb} 90 ref $arg{cb}
63 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 91 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
64 delete $arg{cb}; 92 delete $arg{cb};
65 93
66 eval "require POSIX; defined &POSIX::SIG$arg{signal}" 94 eval "require POSIX; 0 < &POSIX::SIG$arg{signal}"
67 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; 95 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'";
68 delete $arg{signal}; 96 delete $arg{signal};
69 97
70 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 98 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
71 if keys %arg; 99 if keys %arg;
121 and croak "AnyEvent->now wrongly called with paramaters"; 149 and croak "AnyEvent->now wrongly called with paramaters";
122 150
123 $class->SUPER::now (@_) 151 $class->SUPER::now (@_)
124} 152}
125 153
1261 1541;
155
156=head1 AUTHOR
157
158 Marc Lehmann <schmorp@schmorp.de>
159 http://home.schmorp.de/
160
161=cut
162

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines