Evented-Configuration
view release on metacpan or search on metacpan
* block: for unnamed blocks, should be the string block type. for
named blocks, should be an array reference in the form of [block
type, block name].
$conf->on_change($block, $key, $code, %opts)
Attaches an event listener for the configuration change event. This
event will be fired even if the value never existed. If you want a
listener to be called the first time the configuration is parsed,
simply add the listener before calling ->parse_config(). Otherwise, add
listeners later.
# an example with an unnamed block
$conf->on_change('myUnnamedBlock', 'myKey', sub {
my ($event, $old, $new) = @_;
...
});
# an example with a name block.
$conf->on_change(['myNamedBlockType', 'myBlockName'], 'someKey', sub {
my ($event, $old, $new) = @_;
...
});
# an example with an unnamed block and ->register_event() options.
$conf->on_change('myUnnamedBlock', 'myKey', sub {
my ($event, $old, $new) = @_;
...
}, priority => 100, name => 'myCallback');
Parameters
* block: for unnamed blocks, should be the string block type. for
named blocks, should be an array reference in the form of [block
type, block name].
* key: the key of the configuration value being listened for.
* code: a code reference to be called when the value is changed.
* opts: optional, a hash of any other options to be passed to
Evented::Object's ->register_event().
EVENTS
Evented::Configuration fires events when configuration values are
changed.
In any case, events are fired with arguments (old value, new value).
Say you have an unnamed block of type myBlock. If you changed the key
myKey in myBlock, Evented::Configuration would fire the event
change:myBlock:myKey.
Now assume you have a named block of type myBlock with name myName. If
you changed the key myKey in myBlock:myName, Evented::Configuration
would fire event change:myBlock/myName:myKey.
However, it is recommended that you use the ->on_change() method rather
than directly attaching event callbacks. This will insure compatibility
for later versions that could possibly change the way events are fired.
SEE ALSO
* Evented::Object - the event class that powers
Evented::Configuration.
AUTHOR
Mitchell Cooper <https://github.com/cooper> <cooper@cpan.org>
Copyright © 2011-2020. Released under New BSD license.
Comments, complaints, and recommendations are accepted. Bugs may be
reported on GitHub <https://github.com/cooper/evented-object/issues>.
( run in 0.542 second using v1.01-cache-2.11-cpan-39bf76dae61 )