Timer.pm

NAME

Timer

SYNOPSIS

  $timer_laundary = new  Timer;
  $v_laundary_timer = new  Voice_Cmd('Laundary timer [on,off]');
  if ($state =  said $v_laundary_timer) {
    if ($state eq ON) {
       play('rooms' => 'shop', 'file' => 'cloths_started.wav');
       set $timer_laundary 35*60, 'speak "rooms=all The laundary clothes done"', 4;
    }
    else {
      speak 'rooms=shop The laundry timer has been turned off.';
      unset $timer_laundary;
    }
  }

This example uses an anonymous subroutine

  $v_test_delay = new  Voice_Cmd 'Test timer with [1,5,10] seconds';
  if ($state = said $v_test_delay) {
    print_log "Starting $state second timer test";
    my  $timer = new Timer;
    set $timer $state, sub {
      print_log "Ending $state second timer test";
    }
    #      set $timer $state, "print_log 'Ending $state second timer test'";
  }

DESCRIPTION

The Timer object can be used to run an action one or more times, at a specified interval.

INHERITS

METHODS

new

Used to create the object.

set($period, $action, $cycles)

$period is the timer period in seconds $action (optional) is the code (either a string or a code reference) to run when the timer expires $cycles (optional) is how many times to repeat the timer. Set to -1 to repeat forever.

unset

Unset the timer. 'set $my_timer 0' has the same effect.

run_action

Runs the timers action, even if the timer has not expired.

expired

Returns true for the one pass after the timer has expired.

hours_remaining, hours_remaining_now, minutes_remaining, minutes_remaining_now, seconds_remaining, seconds_remaining_now

These methods return the hours, minutes or seconds remaining on the timer. The _now methods only return the remaining time on the hour, minute, or second boundary.

active

Returns true if the timer is still running.

inactive

Returns true if the timer is has expired or has not been set.

start

Starts the timer

restart

Restarts the timer (start on an active timer does nothing)

stop

Stops a timer.

pause

Pauses

resume

Bet you can guess :)

query

Returns the seconds on the timer.

get_type()

Returns the class (or type, in Misterhouse terminology) of this item.

INI PARAMETERS

NONE

AUTHOR

UNK

SEE ALSO

See mh/code/bruce/timers.pl for more examples

LICENSE

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

 Timer.pm