release-1.10release-1.7release-1.8release-1.9
Last change
on this file since b120bd3 was
8d16e58,
checked in by Nelson Elhage <nelhage@mit.edu>, 14 years ago
|
Allow explicitly cancelling timers from perl.
|
-
Property mode set to
100644
|
File size:
788 bytes
|
Line | |
---|
1 | use strict; |
---|
2 | use warnings; |
---|
3 | |
---|
4 | package BarnOwl::Timer; |
---|
5 | |
---|
6 | sub new { |
---|
7 | my $class = shift; |
---|
8 | my $args = shift; |
---|
9 | |
---|
10 | my $cb = $args->{cb}; |
---|
11 | die("Invalid callback pased to BarnOwl::Timer\n") unless ref($cb) eq 'CODE'; |
---|
12 | |
---|
13 | my $self = {cb => $cb}; |
---|
14 | |
---|
15 | bless($self, $class); |
---|
16 | |
---|
17 | $self->{timer} = BarnOwl::Internal::add_timer($args->{after} || 0, |
---|
18 | $args->{interval} || 0, |
---|
19 | $self); |
---|
20 | return $self; |
---|
21 | } |
---|
22 | |
---|
23 | sub stop { |
---|
24 | my $self = shift; |
---|
25 | if(defined($self->{timer})) { |
---|
26 | BarnOwl::Internal::remove_timer($self->{timer}); |
---|
27 | undef $self->{timer}; |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | sub do_callback { |
---|
32 | my $self = shift; |
---|
33 | $self->{cb}->($self); |
---|
34 | } |
---|
35 | |
---|
36 | sub DESTROY { |
---|
37 | my $self = shift; |
---|
38 | $self->stop; |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.