ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV/AnyEvent.pm
Revision: 1.7
Committed: Thu Nov 1 16:01:37 2007 UTC (16 years, 7 months ago) by root
Branch: MAIN
Changes since 1.6: +6 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3     EV::AnyEvent - anyevent adaptor for EV
4    
5     =head1 SYNOPSIS
6    
7 root 1.3 use AnyEvent;
8     use EV;
9    
10     # this module gets loaded automatically as required
11 root 1.1
12     =head1 DESCRIPTION
13    
14 root 1.3 This module provides transparent support for AnyEvent. You don't
15     have to do anything to make EV work with AnyEvent except by loading it
16     beofre creating the firts AnyEvent watcher.
17 root 1.1
18     =cut
19    
20     package EV::AnyEvent;
21    
22     use strict;
23    
24     use EV;
25    
26     sub timer {
27     my ($class, %arg) = @_;
28    
29     EV::timer $arg{after}, 0, $arg{cb}
30     }
31    
32     sub io {
33     my ($class, %arg) = @_;
34    
35     my $cb = $arg{cb};
36    
37     EV::io
38 root 1.2 fileno $arg{fh},
39 root 1.6 ($arg{poll} =~ /r/ ? EV::READ : 0) | ($arg{poll} =~ /w/ ? EV::WRITE : 0),
40 root 1.1 sub {
41     $cb->( ($_[1] & EV::READ ? "r" : "") . ($_[1] & EV::WRITE ? "w" : "") );
42     }
43     }
44    
45 root 1.5 sub signal {
46     my ($class, %arg) = @_;
47    
48     EV::signal $arg{signal}, $arg{cb}
49     }
50 root 1.4
51 root 1.7 sub child {
52     my ($class, %arg) = @_;
53    
54     EV::child $arg{pid}, $arg{cb}
55     }
56    
57 root 1.1 sub condvar {
58     bless \my $flag, "EV::AnyEvent"
59     }
60    
61     sub broadcast {
62     ${$_[0]}++;
63     }
64    
65     sub wait {
66 root 1.6 EV::loop EV::LOOP_ONESHOT
67 root 1.1 while !${$_[0]};
68     }
69    
70     sub one_event {
71 root 1.6 EV::loop EV::LOOP_ONESHOT;
72 root 1.1 }
73    
74     1;
75    
76     =head1 SEE ALSO
77    
78     L<AnyEvent>.
79    
80     =head1 AUTHOR
81    
82     Marc Lehmann <schmorp@schmorp.de>
83     http://home.schmorp.de/
84    
85     =cut
86