NAME
App::PerlWatcher::Engine - Creates Watchers and lets them notify Frontend with their's Statuses
VERSION
version 0.14
SYNOPSIS
# define own frontend in separate package
package My::FrontEnd;
use Moo;
with 'App::PerlWatcher::Frontend';
sub update {
my ( $self, $status ) = @_;
say $status->level;
}
# define engine config with reqired watchers
$config = {
watchers => [
{
class => 'App::PerlWatcher::Watcher::Ping',
config => {
host => 'google.com',
port => 80,
frequency => 10,
timeout => 1,
on => {
fail => {
3 => 'info',
5 => 'warn',
8 => 'alert',
}
ok => { 1 => 'notice'},
},
},
},
],
};
# initialization: bring all pieces together
my $frontend = My::FrontEnd->new(engine => $engine);
my $backend = My::BackEnd->new;
$engine = Engine->new(config => $config, backend => $backend)
$engine->frontend( $app );
$engine->start;
# now if google is down, it says ping status with interpetation
# notice
# notice
# notice
# info
# info
# warn
# ...
ATTRIBUTES
config
Required config, which defines watchers behaviour. See engine.conf.example
backend
AnyEvent supported backed (loop engine), generally defined by using frontend, i.e. for Gtk2-frontend it should call Gtk2->main
statuses_file
Defines, where the Engine state is to be serialized. Default value: $HOME/.perl-watcher/statuses-shelf.data
watchers
An array_ref of Watcher instances. Watchers order is the same as it was defined in config
watchers_order
Return an map "watcher to watcher order".
shelf
Defines statuses shelf, where remembered watcher statuses are stored. It is needed because, where could be statuses, to which user does not payed attention, and they should not be stored.
METHODS
start
Starts all watchers and backend.
stop
Stops backend, all watchers and persists current state (watchers memories and shelf)
sort_statuses
Helper method which sorts statuses in accordance with theirs watchers order
AUTHOR
Ivan Baidakou <dmol@gmx.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Ivan Baidakou.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.