| 1 | package BusyBird::Watcher; | ||
| 2 | 11 | ▶ | use v5.8.0; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 11 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 11 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 11 | 1; | |
| 7 | |||
| 8 | =pod | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | BusyBird::Watcher - interface for watcher objects | ||
| 13 | |||
| 14 | =for test_synopsis | ||
| 15 | my ($timeline); sub callback {} | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | my $watcher = $timeline->watch_unacked_counts( | ||
| 20 | assumed => { total => 0 }, | ||
| 21 | callback => sub { ... } | ||
| 22 | ); | ||
| 23 | |||
| 24 | $watcher->active; ## returns true if the $watcher is active | ||
| 25 | $watcher->cancel(); ## cancels the $watcher | ||
| 26 | |||
| 27 | =head1 DESCRIPTION | ||
| 28 | |||
| 29 | This is an interface (or role) class for watcher objects. | ||
| 30 | A watcher is something that represents a callback registered somewhere. | ||
| 31 | Users can use a watcher to cancel (i.e. unregister) the callback. | ||
| 32 | |||
| 33 | L<BusyBird::Watcher> does not implement any method. | ||
| 34 | Implementations of L<BusyBird::Watcher> must be a subclass of L<BusyBird::Watcher> | ||
| 35 | and implement the following methods. | ||
| 36 | |||
| 37 | =head1 OBJECT METHODS | ||
| 38 | |||
| 39 | =head2 $is_active = $watcher->active() | ||
| 40 | |||
| 41 | Returns true if the C<$watcher> is active. Returns false otherwise. | ||
| 42 | |||
| 43 | An active watcher is the one whose callback can be called. | ||
| 44 | On the other hand, the callback of an inactive watcher will never be called. | ||
| 45 | |||
| 46 | =head2 $watcher->cancel() | ||
| 47 | |||
| 48 | Cancels the C<$watcher>, that is, makes it inactive. | ||
| 49 | |||
| 50 | If C<$watcher> is already inactive, it stays inactive. | ||
| 51 | |||
| 52 | |||
| 53 | =head1 AUTHOR | ||
| 54 | |||
| 55 | Toshio Ito C<< <toshioito [at] cpan.org> >> | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||