ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Strict.pm
Revision: 1.2
Committed: Tue Jul 8 23:54:12 2008 UTC (15 years, 11 months ago) by root
Branch: MAIN
Changes since 1.1: +4 -2 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     my $MODEL = shift @AnyEvent::ISA;
12     unshift @ISA, $MODEL;
13     unshift @AnyEvent::ISA, AnyEvent::Strict::
14     };
15    
16     sub io {
17     my $class = shift;
18     my %arg = @_;
19    
20     ref $arg{cb}
21     or croak "AnyEvent->io called with illegal cb argument '$arg{cb}'";
22     delete $arg{cb};
23    
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]$/
29     or croak "AnyEvent->io called with illegal poll argument '$arg{poll}'";
30     delete $arg{poll};
31    
32     croak "AnyEvent->io called with unsupported parameter(s) " . join ", ", keys %arg
33     if keys %arg;
34    
35     $class->SUPER::io (@_)
36     }
37    
38     sub timer {
39     my $class = shift;
40     my %arg = @_;
41    
42     ref $arg{cb}
43     or croak "AnyEvent->timer called with illegal cb argument '$arg{cb}'";
44     delete $arg{cb};
45    
46     exists $arg{after}
47     or croak "AnyEvent->timer called without mandatory 'after' parameter";
48     delete $arg{after};
49    
50     !$arg{interval} or $arg{interval} > 0
51     or croak "AnyEvent->timer called with illegal interval argument '$arg{interval}'";
52     delete $arg{interval};
53    
54     croak "AnyEvent->timer called with unsupported parameter(s) " . join ", ", keys %arg
55     if keys %arg;
56    
57     $class->SUPER::timer (@_)
58     }
59    
60     sub signal {
61     my $class = shift;
62     my %arg = @_;
63    
64     ref $arg{cb}
65     or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
66     delete $arg{cb};
67    
68     eval "require POSIX; defined &POSIX::SIG$arg{signal}"
69     or croak "AnyEvent->signal called with illegal signal name '$arg{signal}'";
70     delete $arg{signal};
71    
72     croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
73     if keys %arg;
74    
75     $class->SUPER::signal (@_)
76     }
77    
78     sub child {
79     my $class = shift;
80     my %arg = @_;
81    
82     ref $arg{cb}
83     or croak "AnyEvent->signal called with illegal cb argument '$arg{cb}'";
84     delete $arg{cb};
85    
86     $arg{pid} =~ /^-?\d+$/
87     or croak "AnyEvent->signal called with illegal pid value '$arg{pid}'";
88     delete $arg{pid};
89    
90     croak "AnyEvent->signal called with unsupported parameter(s) " . join ", ", keys %arg
91     if keys %arg;
92    
93     $class->SUPER::child (@_)
94     }
95    
96     sub condvar {
97     my $class = shift;
98     my %arg = @_;
99    
100     !exists $arg{cb} or ref $arg{cb}
101     or croak "AnyEvent->condvar called with illegal cb argument '$arg{cb}'";
102     delete $arg{cb};
103    
104     croak "AnyEvent->condvar called with unsupported parameter(s) " . join ", ", keys %arg
105     if keys %arg;
106    
107     $class->SUPER::condvar (@_)
108     }
109    
110     sub time {
111     my $class = shift;
112    
113     @_
114     and croak "AnyEvent->time wrongly called with paramaters";
115    
116     $class->SUPER::time (@_)
117     }
118    
119     sub now {
120     my $class = shift;
121    
122     @_
123     and croak "AnyEvent->now wrongly called with paramaters";
124    
125     $class->SUPER::now (@_)
126     }
127    
128     1