release-1.10release-1.8release-1.9
Last change
on this file since 42a0c8b was
074bdaa,
checked in by David Benjamin <davidben@mit.edu>, 13 years ago
|
Replace BarnOwl::Timer with a perl wrapper over AnyEvent
This also allows us to kill owl_timer altogether.
|
-
Property mode set to
100644
|
File size:
545 bytes
|
Line | |
---|
1 | use strict; |
---|
2 | use warnings; |
---|
3 | |
---|
4 | package BarnOwl::Timer; |
---|
5 | |
---|
6 | use AnyEvent; |
---|
7 | |
---|
8 | sub new { |
---|
9 | my $class = shift; |
---|
10 | my $args = shift; |
---|
11 | |
---|
12 | my $cb = $args->{cb}; |
---|
13 | die("Invalid callback pased to BarnOwl::Timer\n") unless ref($cb) eq 'CODE'; |
---|
14 | |
---|
15 | my $self = {cb => $cb}; |
---|
16 | |
---|
17 | bless($self, $class); |
---|
18 | |
---|
19 | $self->{timer} = AnyEvent->timer(%$args); |
---|
20 | return $self; |
---|
21 | } |
---|
22 | |
---|
23 | sub stop { |
---|
24 | my $self = shift; |
---|
25 | undef $self->{timer}; |
---|
26 | } |
---|
27 | |
---|
28 | sub do_callback { |
---|
29 | my $self = shift; |
---|
30 | $self->{cb}->($self); |
---|
31 | } |
---|
32 | |
---|
33 | sub DESTROY { |
---|
34 | my $self = shift; |
---|
35 | $self->stop; |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.