ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV/AnyEvent.pm
Revision: 1.6
Committed: Wed Oct 31 14:44:35 2007 UTC (16 years, 7 months ago) by root
Branch: MAIN
Changes since 1.5: +3 -3 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 EV::AnyEvent - anyevent adaptor for EV
4
5 =head1 SYNOPSIS
6
7 use AnyEvent;
8 use EV;
9
10 # this module gets loaded automatically as required
11
12 =head1 DESCRIPTION
13
14 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
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 fileno $arg{fh},
39 ($arg{poll} =~ /r/ ? EV::READ : 0) | ($arg{poll} =~ /w/ ? EV::WRITE : 0),
40 sub {
41 $cb->( ($_[1] & EV::READ ? "r" : "") . ($_[1] & EV::WRITE ? "w" : "") );
42 }
43 }
44
45 sub signal {
46 my ($class, %arg) = @_;
47
48 EV::signal $arg{signal}, $arg{cb}
49 }
50
51 sub condvar {
52 bless \my $flag, "EV::AnyEvent"
53 }
54
55 sub broadcast {
56 ${$_[0]}++;
57 }
58
59 sub wait {
60 EV::loop EV::LOOP_ONESHOT
61 while !${$_[0]};
62 }
63
64 sub one_event {
65 EV::loop EV::LOOP_ONESHOT;
66 }
67
68 1;
69
70 =head1 SEE ALSO
71
72 L<AnyEvent>.
73
74 =head1 AUTHOR
75
76 Marc Lehmann <schmorp@schmorp.de>
77 http://home.schmorp.de/
78
79 =cut
80