source: perl/lib/BarnOwl/Timer.pm @ 4b23009

release-1.8release-1.9
Last change on this file since 4b23009 was 074bdaa, checked in by David Benjamin <davidben@mit.edu>, 11 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
RevLine 
[ee183be]1use strict;
2use warnings;
3
4package BarnOwl::Timer;
5
[074bdaa]6use AnyEvent;
7
[ee183be]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
[074bdaa]19    $self->{timer} = AnyEvent->timer(%$args);
[ee183be]20    return $self;
21}
22
[8d16e58]23sub stop {
24    my $self = shift;
[074bdaa]25    undef $self->{timer};
[8d16e58]26}
27
[ee183be]28sub do_callback {
29    my $self = shift;
30    $self->{cb}->($self);
31}
32
33sub DESTROY {
34    my $self = shift;
[8d16e58]35    $self->stop;
[ee183be]36}
37
38
391;
Note: See TracBrowser for help on using the repository browser.