App::PerlShell::Config - Perl Shell Config
use App::PerlShell::Config; my $config = App::PerlShell::Config->new( key => 'value' ); print $config->config; print $config->config('key'); $config->config('key', 'new_value'); print $config->config('key');
App::PerlShell::Config creates a global configuration structure for App::PerlShell applications.
my $config = App::PerlShell::Config->new( key1 => 'value1', key2 => 'value2', ... );
Create a new App::PerlShell::Config object with provided key / value pairs as configuration options.
[$c =] $config->config([OPTIONS]);
Get or set configuration parameters configured with new. This allows a user of App::PerlShell to manipulate configuration parameters but not add new ones with this method interface.
new
In a App::PerlShell program / module, one may choose to subclass this method with:
sub config { $config->config(@_) }
This allows for manipulation of the configuration parameters without knowing the object variable ($config in the above example).
Get all:
[$i =] $config->config(); [%i =] $config->config();
Called with no options, returns all configuration parameters as reference or hash, depending on how it's called. In App::PerlShell, called with no return value simply prints all configuration parameters.
Get one:
[$i =] $config->config('key');
Returns the value of key.
key
Set:
[$i =] $config->config('key','new_value'); [$i =] $config->config(key => 'new_value');
Sets the value of key to 'new_value' and returns the previous value.
$config->add(key [,value]);
Add 'key' with optional 'value' to the App::PerlShell::Config object. If 'value' not provided, 'key' is added with value undef. Returns 1 on success, 0 on failure.
[$c =] $config->delete(key);
Delete 'key' from the App::PerlShell::Config object. Returns 1 on success, 0 on failure.
[$c =] $config->exists(key);
Check if 'key' exists in the App::PerlShell::Config object. Returns 1 if yes, 0 if not.
$conf_file = config_where($conf [,$dir]);
Given a config file name ($conf) and an optional directory ($dir), find the config file and return the full path or undefined if not found.
$conf
$dir
Search order is:
'$conf' in the current working directory where the script is invoked. If found, return value is simply the file name in '$conf', no path.
'$conf' in user's home directory (e.g., $HOME, %USERPROFILE%).
'$conf' in the provided directory '$dir'. This can be any directory, but usually would be the installation directory of the script as such:
use FindBin qw($Bin); ... $conf_file = config_where($conf, $Bin);
If no configuration file is found, returns undefined.
Subroutine config_where can be exported by calling use with:
config_where
use App::PerlShell::Config qw(config_where);
App::PerlShell
This software is released under the same terms as Perl itself. If you don't know what that means visit http://perl.com/.
Copyright (c) 2015 Michael Vincent
http://www.VinsWorld.com
All rights reserved
To install App::PerlShell, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::PerlShell
CPAN shell
perl -MCPAN -e shell install App::PerlShell
For more information on module installation, please visit the detailed CPAN module installation guide.