ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Impl/Glib.pm
Revision: 1.11
Committed: Sun Jul 8 08:52:10 2007 UTC (16 years, 11 months ago) by root
Branch: MAIN
CVS Tags: rel-2_8, rel-2_9, rel-2_6, rel-2_7, rel-3_0, rel-2_55
Changes since 1.10: +1 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package AnyEvent::Impl::Glib;
2
3 no warnings;
4 use strict;
5
6 use Glib ();
7
8 my $maincontext = Glib::MainContext->default;
9
10 sub io {
11 my ($class, %arg) = @_;
12
13 my $self = bless \%arg, $class;
14 my $rcb = \$self->{cb};
15
16 my @cond;
17 # some glibs need hup, others error with it, YMMV
18 push @cond, "in", "hup" if $self->{poll} eq "r";
19 push @cond, "out", "hup" if $self->{poll} eq "w";
20
21 $self->{source} = add_watch Glib::IO fileno $self->{fh}, \@cond, sub {
22 $$rcb->();
23 ! ! $$rcb
24 };
25
26 $self
27 }
28
29 sub timer {
30 my ($class, %arg) = @_;
31
32 my $self = bless \%arg, $class;
33 my $cb = $self->{cb};
34
35 $self->{source} = add Glib::Timeout $self->{after} * 1000, sub {
36 $cb->();
37 0
38 };
39
40 $self
41 }
42
43 sub DESTROY {
44 my ($self) = @_;
45
46 remove Glib::Source delete $self->{source} if $self->{source};
47 # need to undef $cb because we hold references to it
48 $self->{cb} = undef;
49 %$self = ();
50 }
51
52 sub one_event {
53 $maincontext->iteration (1);
54 }
55
56 1
57