ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV/AnyEvent.pm
Revision: 1.4
Committed: Mon Oct 29 07:56:03 2007 UTC (16 years, 7 months ago) by root
Branch: MAIN
Changes since 1.3: +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.1 ($arg{poll} =~ /r/ ? EV::READ : 0) | ($arg{poll} =~ /w/ ? EV::WRITE : 0) | EV::PERSIST,
40     sub {
41     $cb->( ($_[1] & EV::READ ? "r" : "") . ($_[1] & EV::WRITE ? "w" : "") );
42     }
43     }
44    
45 root 1.4 #sub signal {
46     # my ($class, %arg) = @_;
47     #
48     # EV::timer $arg{after}, 0, $arg{cb}
49     #}#d#TODO
50    
51 root 1.1 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_ONCE
61     while !${$_[0]};
62     }
63    
64     sub one_event {
65     EV::loop EV::LOOP_ONCE;
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