< Back to Module Documentation // View in SVN
NAME
whatbot::Timer - Timer functionality for whatbot.
SYNOPSIS
sub something_awesome : GlobalRegEx('do it later') { my ( $self, $message ) = @_; my $medium = $message->origin; $self->timer->enqueue(10, \&done_later, $self, $medium, "it"); return "ok"; } sub done_later { my ( $self, $medium, $what ) = @_; my $response = new whatbot::Message ( from => $medium->me, to => "", content => "I did $what" ); $medium->send_message($response); }
DESCRIPTION
whatbot::Command is a base class, meant to be subclassed by any additional whatbot command or extension. It provides a skeleton structure to create a new command, parses command attributes, and gives the warnings necessary when a command is not implemented properly.
To create a new command, subclass this module using Moose's 'extends' pragma, and override the given methods with your own. Set attributes to your methods to hook into events.
PUBLIC METHODS
- enqueue($when, $sub, [@args ...])
- The only way to really interact with the timer. $when is in seconds -- either seconds since Jan 1 1970, or, if less than 86400, seconds from now. $sub is a reference to any code, and @args, if provided, are passed directly to that subroutine at call-time.
- tick()
- Called every event loop, from the main whatbot class. Runs all code scheduled for this second. If called multiple times per second, only runs once.
INHERITANCE
LICENSE/COPYRIGHT
Be excellent to each other and party on, dudes.