Changeset 1631825 for perlwrap.pm


Ignore:
Timestamp:
Dec 17, 2008, 3:24:26 PM (13 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
f36cd97
Parents:
c675b39
Message:
Implement a perl timer class and minimal interface.

I will document this and add a better API (perhaps through an AnyEvent
impl) in later commits.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perlwrap.pm

    r25cccdc r1631825  
    12281228}
    12291229
     1230package BarnOwl::Timer;
     1231
     1232sub new {
     1233    my $class = shift;
     1234    my $args = shift;
     1235
     1236    my $cb = $args->{cb};
     1237    die("Invalid callback pased to BarnOwl::Timer\n") unless ref($cb) eq 'CODE';
     1238
     1239    my $self = {cb => $cb};
     1240
     1241    bless($self, $class);
     1242
     1243    $self->{timer} = BarnOwl::Internal::add_timer($args->{after} || 0,
     1244                                                  $args->{interval} || 0,
     1245                                                  $self);
     1246    return $self;
     1247}
     1248
     1249sub do_callback {
     1250    my $self = shift;
     1251    $self->{cb}->($self);
     1252}
     1253
     1254sub DESTROY {
     1255    my $self = shift;
     1256    if(defined($self->{timer})) {
     1257        BarnOwl::Internal::remove_timer($self->{timer});
     1258    }
     1259}
     1260
    12301261
    12311262# switch to package main when we're done
Note: See TracChangeset for help on using the changeset viewer.