release-1.10release-1.7release-1.8release-1.9
Last change
on this file since 385cce2 was
385cce2,
checked in by David Benjamin <davidben@mit.edu>, 14 years ago
|
Remove the DESTROY hook in MainLoopCompatHook
It can't cause a timer leak and is causing spew in tests.
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[3aa0522] | 1 | use strict; |
---|
| 2 | use warnings; |
---|
| 3 | |
---|
| 4 | package BarnOwl::MainLoopCompatHook; |
---|
| 5 | |
---|
| 6 | use BarnOwl; |
---|
| 7 | use BarnOwl::Hook; |
---|
| 8 | use BarnOwl::Timer; |
---|
| 9 | use Scalar::Util qw(weaken); |
---|
| 10 | |
---|
| 11 | sub new { |
---|
| 12 | my $class = shift; |
---|
| 13 | my $hook = BarnOwl::Hook->new; |
---|
| 14 | return bless {hook => $hook}, $class; |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | sub check_owlconf { |
---|
| 18 | my $self = shift; |
---|
| 19 | $self->_ensure_timer() if (*BarnOwl::mainloop_hook{CODE}); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | sub run { |
---|
| 23 | my $self = shift; |
---|
| 24 | return $self->{hook}->run(@_); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | sub add { |
---|
| 28 | my $self = shift; |
---|
| 29 | $self->_ensure_timer(); |
---|
| 30 | $self->{hook}->add(@_); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | sub clear { |
---|
| 34 | my $self = shift; |
---|
| 35 | $self->_kill_timer() unless *BarnOwl::mainloop_hook{CODE}; |
---|
| 36 | $self->{hook}->clear(); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | sub _ensure_timer { |
---|
| 40 | my $self = shift; |
---|
| 41 | BarnOwl::debug("Enabling backwards-compatibility \"main loop\" hook"); |
---|
| 42 | my $weak = $self; |
---|
| 43 | weaken($weak); |
---|
| 44 | unless ($self->{timer}) { |
---|
| 45 | $self->{timer} = BarnOwl::Timer->new( { |
---|
| 46 | after => 0, |
---|
| 47 | interval => 1, |
---|
| 48 | cb => sub { |
---|
| 49 | $weak->run if $weak; |
---|
| 50 | BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE}; |
---|
| 51 | }, |
---|
| 52 | } ); |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | sub _kill_timer { |
---|
| 57 | my $self = shift; |
---|
| 58 | if ($self->{timer}) { |
---|
| 59 | $self->{timer}->stop; |
---|
| 60 | undef $self->{timer}; |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.