ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Strict.pm
Revision: 1.4
Committed: Wed Jul 9 11:00:02 2008 UTC (15 years, 10 months ago) by root
Branch: MAIN
Changes since 1.3: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 package AnyEvent::Strict;
2    
3 root 1.2 # supply checks for argument validity for many functions
4     # this is an internal module. although it could be loaded
5     # at any time, this is not really documented.
6    
7 root 1.1 use Carp qw(croak);
8     use AnyEvent ();
9    
10     AnyEvent::post_detect {
11 root 1.3 # assume the first ISA member is the implementation
12     # # and link us in before it in the chain.
13 root 1.1 my $MODEL = shift @AnyEvent::ISA;
14     unshift @ISA, $MODEL;
15     unshift @AnyEvent::ISA, AnyEvent::Strict::
16     };
17    
18     sub io {
19     my $class = shift;
20     my %arg = @_;
21    
22     ref $arg{cb}
23     or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'";
24     delete $arg{cb};
25    
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]$/
31     or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'";
32     delete $arg{poll};
33    
34     croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg
35     if keys %arg;
36    
37     $class->SUPER::io (@_)
38     }
39    
40     sub timer {
41     my $class = shift;
42     my %arg = @_;
43    
44     ref $arg{cb}
45     or croak "AnyEvent->timer called with illegal cb argument '$arg{cb}'";
46     delete $arg{cb};
47    
48     exists $arg{after}
49     or croak "AnyEvent->timer called without mandatory 'after' parameter";
50     delete $arg{after};
51    
52     !$arg{interval} or $arg{interval} > 0
53     or croak "AnyEvent->timer called with illegal interval argument '$arg{interval}'";
54     delete $arg{interval};
55    
56     croak "AnyEvent->timer called with unsupported parameter(s) " . join ", ", keys %arg
57     if keys %arg;
58    
59     $class->SUPER::timer (@_)
60     }
61    
62     sub signal {
63     my $class = shift;
64     my %arg = @_;
65    
66     ref $arg{cb}
67     or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
68     delete $arg{cb};
69    
70 root 1.4 eval "require POSIX; 0 < &POSIX::SIG$arg{signal}"
71 root 1.1 or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'";
72     delete $arg{signal};
73    
74     croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
75     if keys %arg;
76    
77     $class->SUPER::signal (@_)
78     }
79    
80     sub child {
81     my $class = shift;
82     my %arg = @_;
83    
84     ref $arg{cb}
85     or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
86     delete $arg{cb};
87    
88     $arg{pid} =~ /^-?\d+$/
89     or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'";
90     delete $arg{pid};
91    
92     croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
93     if keys %arg;
94    
95     $class->SUPER::child (@_)
96     }
97    
98     sub condvar {
99     my $class = shift;
100     my %arg = @_;
101    
102     !exists $arg{cb} or ref $arg{cb}
103     or croak "AnyEvent->condvar called with illegal cb argument '$arg{cb}'";
104     delete $arg{cb};
105    
106     croak "AnyEvent->condvar called with unsupported parameter(s) " . join ", ", keys %arg
107     if keys %arg;
108    
109     $class->SUPER::condvar (@_)
110     }
111    
112     sub time {
113     my $class = shift;
114    
115     @_
116     and croak "AnyEvent->time wrongly called with paramaters";
117    
118     $class->SUPER::time (@_)
119     }
120    
121     sub now {
122     my $class = shift;
123    
124     @_
125     and croak "AnyEvent->now wrongly called with paramaters";
126    
127     $class->SUPER::now (@_)
128     }
129    
130     1