The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

POSIX::RT::Timer - POSIX real-time timers

VERSION

Version 0.008

SYNOPSIS

 use POSIX::RT::Timer;

 my $timer = POSIX::RT::Timer->new(value => 1, callback => sub {
     my $timer = shift;
         # do something
 });

DESCRIPTION

This module provides for timers. Unlike getitimer/setitimer an arbitrary number of timers is supported. There are two kinds of timers: signal timers and callback timers.

Signal timers send a signal to the process, much like itimers. You can specify which signal is sent, using realtime signals is recommended.

Callback timers call a callback on expiration. They are actually implemented by a signal handler on $POSIX::RT::Timer::SIGNO. The value of this variable can be set before loading this module. Callbacks are called with the timer as their only argument.

METHODS

Class methods

  • new(%options)

    Create a new timer. Options include

    • value = 0

      The time in factional seconds for timer expiration. If it is 0 the timer is disarmed.

    • interval = 0

      The value the timer is set to after expiration. If this is set to 0, it is a one-shot timer.

    • clock = 'realtime'

      The type of clock

    • signal

      The signal number to send a signal to on timer expiration.

    • callback

      The callback to call on timer expiration. The callback will receive the timer as its only arguments.

    Signal and callback options are mutually exclusive. It is mandatory to set one of these. Signal timers can not be converted into callback timers or reverse.

  • get_clocks()

    Get a list of all supported clocks by their names.

Instance methods

  • get_timeout()

    Get the timeout value. In list context, it also returns the interval value. Note that this value is always relative to the current time.

  • set_timeout($value, $interval = 0, $abstime = 0)

    Set the timer and interval values. If $abstime is true, they are absolute values, otherwise they are relative to the current time. Returns the old value like get_time does.

  • get_overrun()

    Get the overrun count for the timer. The timer overrun count is the number of additional timer expirations that occurred since the signal was sent.

  • get_callback()

    Get the callback function.

  • set_callback($callback)

    Set the callback function.

AUTHOR

Leon Timmermans, <leont at cpan.org>

BUGS

Perl can interact weirdly with signals. Beware of the dragons.

POSIX::RT::Timer currently uses an unsafe signal handler for callback handlers.

Please report any bugs or feature requests to bug-posix-rt-timer at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POSIX-RT-Timer. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc POSIX::RT::Timer

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2010 Leon Timmermans.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.