ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Impl/Event.pm
Revision: 1.30
Committed: Thu Jul 9 22:49:18 2009 UTC (14 years, 11 months ago) by root
Branch: MAIN
CVS Tags: rel-4_83, rel-4_82
Changes since 1.29: +4 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.16 =head1 NAME
2    
3     AnyEvent::Impl::Event - AnyEvent adaptor for Event
4    
5     =head1 SYNOPSIS
6    
7 root 1.21 use AnyEvent;
8 root 1.25 use Event;
9 root 1.21
10     # this module gets loaded automatically as required
11 root 1.16
12     =head1 DESCRIPTION
13    
14     This module provides transparent support for AnyEvent. You don't have to
15     do anything to make Event work with AnyEvent except by loading Event before
16     creating the first AnyEvent watcher.
17    
18 root 1.24 The event module is reasonably efficient and generally works correctly
19     even with many watchers.
20    
21 root 1.16 =cut
22    
23 root 1.1 package AnyEvent::Impl::Event;
24    
25 root 1.12 no warnings;
26 root 1.15 use strict;
27 root 1.12
28 root 1.20 use AnyEvent ();
29 root 1.19
30 root 1.27 use Event qw(unloop); # we have to import something to make Event use Time::HiRes
31 root 1.1
32 root 1.2 sub io {
33     my ($class, %arg) = @_;
34     $arg{fd} = delete $arg{fh};
35 root 1.20 $arg{poll} .= "e" if AnyEvent::WIN32; # work around windows connect bug
36 root 1.30 my $cb = $arg{cb}; $arg{cb} = sub { &$cb }; # event doesn't like callable objects
37 root 1.13 bless \(Event->io (%arg)), $class
38 root 1.2 }
39    
40     sub timer {
41     my ($class, %arg) = @_;
42 root 1.28 $arg{after} = 0 if $arg{after} < 0;
43 root 1.30 my $cb = $arg{cb}; $arg{cb} = sub { &$cb }; # event doesn't like callable objects
44 root 1.23 bless \Event->timer (%arg, repeat => $arg{interval}), $class
45 root 1.2 }
46    
47 root 1.13 sub signal {
48     my ($class, %arg) = @_;
49 root 1.30 my $cb = $arg{cb}; $arg{cb} = sub { &$cb }; # event doesn't like callable objects
50 root 1.18 bless \Event->signal (%arg), $class
51 root 1.13 }
52    
53 root 1.27 sub idle {
54     my ($class, %arg) = @_;
55 root 1.30 my $cb = $arg{cb}; $arg{cb} = sub { &$cb }; # event doesn't like callable objects
56 root 1.27 bless \Event->idle (repeat => 1, min => 0, %arg), $class
57     }
58    
59 root 1.7 sub DESTROY {
60 root 1.9 ${$_[0]}->cancel;
61 root 1.1 }
62    
63 root 1.11 sub one_event {
64     Event::one_event;
65 root 1.1 }
66    
67 root 1.29 sub loop {
68     Event::loop;
69     }
70    
71 root 1.16 1;
72    
73     =head1 SEE ALSO
74    
75 root 1.17 L<AnyEvent>, L<Event>.
76 root 1.16
77     =head1 AUTHOR
78    
79     Marc Lehmann <schmorp@schmorp.de>
80     http://home.schmorp.de/
81    
82     =cut
83 root 1.1