NAME

Config::Reload - Load config files, reload when files changed.

VERSION

version 0.21

SYNOPSIS

my $config = Config::Reload->new(
    wait => 60,     # check at most every minute (default)
    ...             # passed to Config::ZOMG, e.g. file => $filename
);

my $config = $config->load;

sleep(60);

$config = $config->load;   # reloaded

DESCRIPTION

This Perl package loads config files via Config::ZOMG which is based on Config::Any. Configuration is reloaded on file changes (based on file names and last modification time).

This package is highly experimental and not fully covered by unit tests!

METHODS

new

Returns a new Config::Reload object. All arguments but wait, error and checked are passed to the constructor of Config::ZOMG.

load

Get the configuration, possibly (re)loading configuration files. Always returns a hash reference, on error this { } .

wait

Get or set the number of seconds to wait between checking. Set to 60 (one minute) by default.

checked

Returns a timestamp of last time files had been checked.

loaded

Returns a timestamp of last time files had been loaded. Returns undef before first loading and on error.

found

Returns a list of files that configuration has been loaded from.

find

Returns a list of files that configuration will be loaded from on next check. Files will be reloaded only if files_hash value of of find differs from the value of found:

use Config::Reload qw(files_hash);

files_hash( $config->find ) ne files_hash( $config->found )

error

Returns an error message if loading failed. As long as an error is set, the load method returns an empty hash reference until the next attempt to reload (typically the time span defind with wait). One can manually unset the error with $c->error(undef) to force reloading.

FUNCTIONS

files_hash( @files )

Returns a hexadecimal MD5 value based on names, -sizes and modification times of a list of files. Internally used to compare find and found.

This function can be exported on request.

AUTHOR

Jakob Voß

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Jakob Voß.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.