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.7 by root, Tue Jan 13 22:37:18 2009 UTC vs.
Revision 1.18 by root, Wed Jul 29 12:39:21 2009 UTC

3AnyEvent::Strict - force strict mode on for the whole process 3AnyEvent::Strict - force strict mode on for the whole process
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use AnyEvent::Strict; 7 use AnyEvent::Strict;
8 # struct mode now switched on 8 # strict mode now switched on
9 9
10=head1 DESCRIPTION 10=head1 DESCRIPTION
11 11
12This module implements AnyEvent's strict mode. 12This module implements AnyEvent's strict mode.
13 13
22=cut 22=cut
23 23
24package AnyEvent::Strict; 24package AnyEvent::Strict;
25 25
26use Carp qw(croak); 26use Carp qw(croak);
27use Fcntl ();
27 28
28use AnyEvent (); 29use AnyEvent (); BEGIN { AnyEvent::common_sense }
30
31our @ISA;
29 32
30AnyEvent::post_detect { 33AnyEvent::post_detect {
31 # assume the first ISA member is the implementation 34 # assume the first ISA member is the implementation
32 # # and link us in before it in the chain. 35 # # and link us in before it in the chain.
33 my $MODEL = shift @AnyEvent::ISA; 36 my $MODEL = shift @AnyEvent::ISA;
41 44
42 ref $arg{cb} 45 ref $arg{cb}
43 or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'"; 46 or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'";
44 delete $arg{cb}; 47 delete $arg{cb};
45 48
46 defined fileno $arg{fh}
47 or croak "AnyEvent->io called with illegal fh argument '$arg{fh}'";
48 delete $arg{fh};
49
50 $arg{poll} =~ /^[rw]$/ 49 $arg{poll} =~ /^[rw]$/
51 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
52 delete $arg{poll}; 62 delete $arg{poll};
63 delete $arg{fh};
53 64
54 croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg 65 croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg
55 if keys %arg; 66 if keys %arg;
56 67
57 $class->SUPER::io (@_) 68 $class->SUPER::io (@_)
85 96
86 ref $arg{cb} 97 ref $arg{cb}
87 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 98 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
88 delete $arg{cb}; 99 delete $arg{cb};
89 100
90 eval "require POSIX; 0 < &POSIX::SIG$arg{signal}" 101 defined AnyEvent::Base::sig2num $arg{signal}
91 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'"; 102 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'";
92 delete $arg{signal}; 103 delete $arg{signal};
93 104
94 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 105 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
95 if keys %arg; 106 if keys %arg;
100sub child { 111sub child {
101 my $class = shift; 112 my $class = shift;
102 my %arg = @_; 113 my %arg = @_;
103 114
104 ref $arg{cb} 115 ref $arg{cb}
105 or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'"; 116 or croak "AnyEvent->child called with illegal cb argument '$arg{cb}'";
106 delete $arg{cb}; 117 delete $arg{cb};
107 118
108 $arg{pid} =~ /^-?\d+$/ 119 $arg{pid} =~ /^-?\d+$/
109 or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'"; 120 or croak "AnyEvent->child called with malformed pid value '$arg{pid}'";
110 delete $arg{pid}; 121 delete $arg{pid};
111 122
112 croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg 123 croak "AnyEvent->child called with unsupported parameter(s) " . join ", ", keys %arg
113 if keys %arg; 124 if keys %arg;
114 125
115 $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 (@_)
116} 141}
117 142
118sub condvar { 143sub condvar {
119 my $class = shift; 144 my $class = shift;
120 my %arg = @_; 145 my %arg = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines