NAME
App::PerlWatcher::Watcher - Observes some external source of events and emits the result of polling them
VERSION
version 0.20
ATTRIBUTES
engine_config
Holds an reference to engine config (used in construction watcher's thresholds_map)
init_args
Remembers the arguments for watcher construction (used in construction watcher's thresholds_map and unique_id)
config
The wacher configuration hash ref.
unique_id
Represents watchers unique_id, calculated from concrete watcher class and watcher's config. The unique_id is overloaded "to-string" operation, so watcher can be used to as hash key. unique_id is also used when the PerlWatcher state is been persisted : the watcher itself isn't stored, but it's unique_id is stored. That guarantees that unique_id is the same between PerlWatcher invokations (that's why the perl internal hash funciton isn't used)
active
Memorizable attribute, defines, weather the current watcher is active
thresholds_map
The memorizable map, which represents how to interpret successul or unsuccessful result, i.e. which level of severity it is. It looks like:
my $map = {
fail => {
3 => 'info',
5 => 'alert',
},
ok => { 3 => 'notice' },
};
last_status
Represents last emitted watcher status
poll_callback
The subroutine reference, which is been called before every poll of watcher external source.
$watcher->poll_callback($watcher);
callback
The subroutine reference, which is been called after every poll of watcher external source. It's argument is the State, i.e.
$watcher->callback($state)
watcher_guard
The watcher guard returned by AnyEvent->io, AnyEvent->timer etc, with is an core under wich the Watcher is been build.
METHODS
build_watcher_guard
The method is responsible for building watcher_guard
force_poll
Immediatly polls the watched object.
activate
Turns on and off the wacher, remembering the state in memory
start
Starts the watcher, which will emit it's statuses. The watcher will start only it is active.
calculate_threshods
Calculates the thresholds_map based on the left map and righ map The left map has precedence. Usualy the left map is the watchers config, while the righ map is the generic PerlWatcher/Engine config
interpret_result
This method interprets the result of poll (true or false) in accordance with thresholds_map and the callback will be called with the resulting status (and optionally provided items). Meant to be called from subclases, e.g.
$watcher->interpret_result(0, $callback);
The items can be tacken from the previous result interpreation if they match by content
$items is an coderef, which actually returns array of items.
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.