AnyEvent::Processor - Base class to define an event-driven (AnyEvent) task that could periodically be interrupted by a watcher
version 0.006
package FridgeMonitoring; use Moose; extends 'AnyEvent::Processor'; use TemperatureSensor; has sensors => (is => 'rw', isa => 'ArrayRef[TemperatureSensor]'); has min => (is => 'rw', isa => 'Int', default => '10'); has max => (is => 'rw', isa => 'Int', default => '20'); sub process { my $self = shift; my @failed; for my $sensor ( @{$self->sensors} ) { next if $self->sensor->temperature >= $self->min && $self->sensor->temperature <= $self->max; push @failed, $sensor; } if ( @failed ) { # Send an email to someone with the list of failed fridges } } sub process_message { my $self = shift; say "[", $self->count, "] Fridges testing"; }
package Main;
use FridgeMonitoring;
my $processor = FridgeMonitoring->new( sensors => # Get a list of fridge sensors from somewhere min => 0, max => 40, ); $processor->run();
A processor task based on this class process anything that can be divided into processing clusters. Each cluster is processed one by one by calling the process() method. A count is incremented at the end of each cluster. By default, a AnyEvent::Processor::Watcher is associated with the class, interrupting the processing each second for calling process_message.
process_message
Verbose mode. In this mode an AnyEvent::Processor::Watcher is automatically created, with a 1s timeout, and action directly sent to this class. You can create your own watcher subclassing AnyEvent::Processor::Watcher.
An AnyEvent::Processor::Watcher.
Number of items which have been processed.
Is it a blocking task (not a task). False by default.
Run the process.
Something to do at beginning of the process.
Something to say about the process. Called by default watcher when verbose mode is enabled. By default, just send to STDOUT 'Start process...'. Your class can display another message, or do something else, like sending an email, or a notification to a monitoring system like Nagios.
Process something and increment count. This method has to be surclassed by you class if you want to do someting else than incrementing the count attribute.
count
Say something about the process. Called by default watcher (verbose mode) each 1s. By default, just display the count value. Your processor can display something else than just the number of processing clusters already processed. If your processor monitor the temperature of your fridge, you can display it...
Do something at the end of the process.
Say something at the end of the process. Called by default watcher.
AnyEvent::Processor::Converion
AnyEvent::Processor::Watcher
Frédéric Demians <f.demians@tamil.fr>
This software is Copyright (c) 2015 by Fréderic Demians.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007
2 POD Errors
The following errors were encountered while parsing the POD:
Unterminated L<...> sequence
To install AnyEvent::Processor, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::Processor
CPAN shell
perl -MCPAN -e shell install AnyEvent::Processor
For more information on module installation, please visit the detailed CPAN module installation guide.