Bot-Cobalt
view release on metacpan or search on metacpan
lib/Bot/Cobalt/Timer.pm view on Meta::CPAN
event => 'my_timed_event',
args => [ $one, $two ],
);
$timer->delay(30);
## Add this instance to Core's TimerPool, for example:
$core->timer_set( $timer );
=head1 DESCRIPTION
A B<Bot::Cobalt::Timer> instance represents a single timed event.
These are usually constructed for use by the L<Bot::Cobalt::Core> TimerPool;
also see L<Bot::Cobalt::Core::Role::Timers/timer_set>.
By default, timers that are executed will fire against the
L<Bot::Cobalt::Core> singleton. You can pass in a different 'core =>'
object; it simply needs to provide a C<send_event> method that is passed the
L</event> and L</args> when the timer fires (see L</Execution>).
=head1 METHODS
=head2 Timer settings
=head3 at
The absolute time that this timer is supposed to fire (epoch seconds).
This is normally set automatically when L</delay> is called.
(If it is tweaked manually, L</delay> is irrelevant information.)
=head3 delay
The time this timer is supposed to fire expressed in seconds from the
time it was set.
(Sets L</at> to I<time()> + I<delay>)
=head3 event
The name of the event that should be fired via B<send_event> when this
timer is executed.
=head3 args
A L<List::Objects::WithUtils::Array> containing any arguments attached to the
L</event>.
=head3 id
This timer's unique identifier, used as a key in timer pools.
Note that a unique random ID is added when the Timer object is passed to
L<Bot::Cobalt::Core::Role::Timers/timer_set> if no B<id> is explicitly
specified.
=head3 alias
The alias tag attached to this timer. Defaults to C<caller()>
=head3 type
The type of event.
Valid types as of this writing are B<msg>, B<action>, and B<event>.
B<msg> and B<action> types require L</context>, L</text>, and L</target>
attributes be specified.
If no type has been specified for this timer, B<type()> returns our best
guess; for timed events carrying a L</context> and L</target> the
default is B<msg>.
This is used to set up proper event names for special timer types.
=head3 context
B<msg and action timer types only>
The server context for an outgoing B<msg> or B<action>.
See L</type>
=head3 text
B<msg and action timer types only>
The text string to send with an outgoing B<msg> or B<action>.
See L</type>
=head3 target
B<msg and action timer types only>
The target channel or nickname for an outgoing B<msg> or B<action>.
See L</type>
=head2 Execution
A timer object can be instructed to execute as long as it was provided a
proper B<core> object at construction time (normally L<Bot::Cobalt::Core>).
=head3 is_ready
Returns boolean true if the timer is ready to execute; in other words,
if the specified L</at> is reached.
=head3 execute_if_ready
L</execute> the timer if L</is_ready> is true.
=head3 execute
Execute the timer; if our B<core> object can B<send_event>, the timer's
event is broadcast. Otherwise the timer will warn and return.
=head1 AUTHOR
( run in 1.269 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )