PFT::Conf - Configuration parser for PFT
PFT::Conf->new_default() # Using default PFT::Conf->new_load($root) # Load from conf file in directory PFT::Conf->new_load_locate() # Load from conf file, find directory PFT::Conf->new_load_locate($cwd) PFT::Conf::locate() # Locate root PFT::Conf::locate($cwd) PFT::Conf::isroot($path) # Check if location exists under path. use Getopt::Long; Getopt::Long::Configure 'bundling'; GetOptions( PFT::Conf::wire_getopt(\my %opts), 'more-opt' => \$more, ); PFT::Conf->new_getopt(\%opts); # Create with command line options
Automatic loader and handler for the configuration file of a PFT site.
The configuration is a simple YAML file with a conventional name. Some keys are mandatory, while other are optional. This module allows a headache free check for mandatory ones.
Many constructors are available, here described:
Creates a new configuration based on environment variables and common sense.
The configuration can later be stored on a file with the save_to method.
save_to
Loads a configuration file which must already exist. Accepts as optional argument the name of a directory (not encoded), which defaults on the current directory.
This constructor fails with croak if the directory does not contain a configuration file.
croak
Works as new_load, but before failing makes an attempt to locate the configuration file in the parent directories up to the root level.
new_load
This is handy for launching commands from the command line without worrying on the current directory: it works as long as your cwd is below a PFT root directory.
This is a two-steps constructor meant for command line initializers.
An example of usage can be found in the SYNOPSIS section. In short, the auxiliary function PFT::Conf::wire_getopt provides a list of ready-to-use options for the GetOpt::Long Perl module. It expects a hash reference as argument, which will be used as storage for selected options. The new_getopt constructor expects as argument the same hash reference.
PFT::Conf::wire_getopt
GetOpt::Long
new_getopt
$PFT::Conf::CONF_NAME is a string. Defines the name of the configuration file.
$PFT::Conf::CONF_NAME
The PFT::Conf::isroot function searches for the configuration file in the given directory path (not encoded).
PFT::Conf::isroot
Returns undef if the file was not found, and the encoded file name (according to locale) if it was found.
undef
The PFT::Conf::locate function locates a PFT configuration file.
PFT::Conf::locate
It accepts as optional parameter a directory path (not encoded), defaulting on the current working directory.
Possible return values:
Save the configuration to a file. This will also update the inner root reference, so the intsance will point to the saved file.
To install PFT, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PFT
CPAN shell
perl -MCPAN -e shell install PFT
For more information on module installation, please visit the detailed CPAN module installation guide.