source: perl/lib/BarnOwl/Timer.pm @ 00adc24

release-1.10release-1.8release-1.9
Last change on this file since 00adc24 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 
1use strict;
2use warnings;
3
4package BarnOwl::Timer;
5
6use AnyEvent;
7
8sub 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
23sub stop {
24    my $self = shift;
25    undef $self->{timer};
26}
27
28sub do_callback {
29    my $self = shift;
30    $self->{cb}->($self);
31}
32
33sub DESTROY {
34    my $self = shift;
35    $self->stop;
36}
37
38
391;
Note: See TracBrowser for help on using the repository browser.