Config::PL - Using '.pl' file as a configuration
use Config::PL; my $config = config_do 'config.pl'; my %config = config_do 'config.pl';
Config::PL is a utility module for using '.pl' file as a configuration.
This module provides config_do function for loading '.pl' file.
config_do
Using '.pl' file which returns HashRef as a configuration is good idea. We can write flexible and DRY configuration by it. (But, sometimes it becomes too complicated :P)
do "$file" idiom is often used for loading configuration.
do "$file"
But, there is some problems and Config::PL cares these problems.
do EXPR function of Perl core is not sane because it does not die when the file contains parse error or is not found.
do EXPR
config_do function croaks errors and ensures that the returned value is HashRef.
do "$file" searches files in @INC. It sometimes causes intended file loading.
@INC
config_do function limits the search path only in cwd and basename(__FILE__).
cwd
basename(__FILE__)
You can easily load another configuration file in the config files as follows.
# config.pl use Config:PL; config_do "$ENV{PLACK_ENV}.pl";
You need not write do File::Spec->catfile(File::Basename::dirname(__FILE__), 'config.pl') ... any more!
do File::Spec->catfile(File::Basename::dirname(__FILE__), 'config.pl') ...
You can add search path by specifying path as follows. (EXPERIMENTAL)
use Config::PL ':path' => 'path/config/dir';
THIS SOFTWARE IS IN ALPHA QUALITY. IT MAY CHANGE THE API WITHOUT NOTICE.
my ($conf|%conf) = config_do $file_name;
Loading configuration from '.pl' file.
Copyright (C) Masayuki Matsuki.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Masayuki Matsuki <y.songmu@gmail.com>
To install Config::PL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Config::PL
CPAN shell
perl -MCPAN -e shell install Config::PL
For more information on module installation, please visit the detailed CPAN module installation guide.