| 1 |
NAME |
| 2 |
AnyEvent::Processor - Base class to define an event-driven (AnyEvent) |
| 3 |
task that could periodically be interrupted by a watcher |
| 4 |
|
| 5 |
VERSION |
| 6 |
version 0.006 |
| 7 |
|
| 8 |
SYNOPSIS |
| 9 |
package FridgeMonitoring; |
| 10 |
|
| 11 |
use Moose; |
| 12 |
extends 'AnyEvent::Processor'; |
| 13 |
use TemperatureSensor; |
| 14 |
|
| 15 |
has sensors => (is => 'rw', isa => 'ArrayRef[TemperatureSensor]'); |
| 16 |
has min => (is => 'rw', isa => 'Int', default => '10'); |
| 17 |
has max => (is => 'rw', isa => 'Int', default => '20'); |
| 18 |
|
| 19 |
|
| 20 |
sub process { |
| 21 |
my $self = shift; |
| 22 |
|
| 23 |
my @failed; |
| 24 |
for my $sensor ( @{$self->sensors} ) { |
| 25 |
next if $self->sensor->temperature >= $self->min && |
| 26 |
$self->sensor->temperature <= $self->max; |
| 27 |
push @failed, $sensor; |
| 28 |
} |
| 29 |
if ( @failed ) { |
| 30 |
# Send an email to someone with the list of failed fridges |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
sub process_message { |
| 35 |
my $self = shift; |
| 36 |
say "[", $self->count, "] Fridges testing"; |
| 37 |
} |
| 38 |
|
| 39 |
package Main; |
| 40 |
|
| 41 |
use FridgeMonitoring; |
| 42 |
|
| 43 |
my $processor = FridgeMonitoring->new( sensors => # Get a list of fridge |
| 44 |
sensors from somewhere min => 0, max => 40, ); $processor->run(); |
| 45 |
|
| 46 |
DESCRIPTION |
| 47 |
A processor task based on this class process anything that can be |
| 48 |
divided into processing clusters. Each cluster is processed one by one |
| 49 |
by calling the process() method. A count is incremented at the end of |
| 50 |
each cluster. By default, a AnyEvent::Processor::Watcher is associated |
| 51 |
with the class, interrupting the processing each second for calling |
| 52 |
"process_message". |
| 53 |
|
| 54 |
ATTRIBUTES |
| 55 |
verbose |
| 56 |
Verbose mode. In this mode an AnyEvent::Processor::Watcher is |
| 57 |
automatically created, with a 1s timeout, and action directly sent to |
| 58 |
this class. You can create your own watcher subclassing |
| 59 |
AnyEvent::Processor::Watcher. |
| 60 |
|
| 61 |
watcher |
| 62 |
An AnyEvent::Processor::Watcher. |
| 63 |
|
| 64 |
count |
| 65 |
Number of items which have been processed. |
| 66 |
|
| 67 |
blocking |
| 68 |
Is it a blocking task (not a task). False by default. |
| 69 |
|
| 70 |
METHODS |
| 71 |
run |
| 72 |
Run the process. |
| 73 |
|
| 74 |
start_process |
| 75 |
Something to do at beginning of the process. |
| 76 |
|
| 77 |
start_message |
| 78 |
Something to say about the process. Called by default watcher when |
| 79 |
verbose mode is enabled. By default, just send to STDOUT 'Start |
| 80 |
process...'. Your class can display another message, or do something |
| 81 |
else, like sending an email, or a notification to a monitoring system |
| 82 |
like Nagios. |
| 83 |
|
| 84 |
process |
| 85 |
Process something and increment count. This method has to be surclassed |
| 86 |
by you class if you want to do someting else than incrementing the |
| 87 |
"count" attribute. |
| 88 |
|
| 89 |
process_message |
| 90 |
Say something about the process. Called by default watcher (verbose |
| 91 |
mode) each 1s. By default, just display the "count" value. Your |
| 92 |
processor can display something else than just the number of processing |
| 93 |
clusters already processed. If your processor monitor the temperature of |
| 94 |
your fridge, you can display it... |
| 95 |
|
| 96 |
end_process |
| 97 |
Do something at the end of the process. |
| 98 |
|
| 99 |
end_message |
| 100 |
Say something at the end of the process. Called by default watcher. |
| 101 |
|
| 102 |
SEE ALSO |
| 103 |
* AnyEvent::Processor::Converion |
| 104 |
|
| 105 |
* AnyEvent::Processor::Watcher |
| 106 |
|
| 107 |
AUTHOR |
| 108 |
Frédéric Demians <[email protected]> |
| 109 |
|
| 110 |
COPYRIGHT AND LICENSE |
| 111 |
This software is Copyright (c) 2015 by Fréderic Demians. |
| 112 |
|
| 113 |
This is free software, licensed under: |
| 114 |
|
| 115 |
The GNU General Public License, Version 3, June 2007 |
| 116 |
|
| 117 |
POD ERRORS |
| 118 |
Hey! The above document had some coding errors, which are explained |
| 119 |
below: |
| 120 |
|
| 121 |
Around line 230: |
| 122 |
Unterminated L<...> sequence |
| 123 |
|
| 124 |
Around line 234: |
| 125 |
Unterminated L<...> sequence |
| 126 |
|