Config-Fast
view release on metacpan or search on metacpan
lib/Config/Fast.pm view on Meta::CPAN
fastconfig('web.conf');
print "The web address is: $website\n"; # website from conf
Generally, this is regarded as B<dangerous> and bad form, so I would
strongly advise using this form only in throwaway scripts, or not at
all.
=head1 VARIABLES
There are several global variables that can be set which affect how
C<fastconfig()> works. These can be set in the following way:
use Config::Fast;
$Config::Fast::Variable = 'value';
%cf = fastconfig;
The recognized variables are:
=over
=item $Delim
The config file delimiter to use. This can also be specified as the second
argument to C<fastconfig()>. This defaults to C<\s+>.
=item $KeepCase
If set to 1, then C<MixedCaseVariables> are maintained intact. By default,
all variables are converted to lowercase.
=item $EnvCaps
If set to 1 (the default), then any C<ALLCAPS> variables are set as
environment variables. They are still returned in lowercase from
C<fastconfig()>.
=item $Arrays
If set to 1, then settings that look like shell arrays are converted into
a Perl array. For example, this config block:
MATRIX[0]="a b c"
MATRIX[1]="d e f"
MATRIX[2]="g h i"
Would be returned as:
$conf{matrix} = [ 'a b c', 'd e f', 'g h i' ];
Instead of the default:
$conf{matrix[0]} = 'a b c';
$conf{matrix[1]} = 'd e f';
$conf{matrix[2]} = 'g h i';
=item @Define
This allows you to pre-define var=val pairs that are set before the parsing
of the config file. I introduced this feature to solve a specific problem:
Executable relocation. In my config files, I put definitions such as:
# Parsed by Config::Fast and sourced by shell scripts
BIN="$ROOT/bin"
SBIN="$ROOT/sbin"
LIB="$ROOT/lib"
ETC="$ROOT/etc"
With the goal that this file would be equally usable by both Perl and
shell scripts.
When parsed by C<Config::Fast>, I pre-define C<ROOT> to C<pwd> before
calling C<fastconfig()>:
use Cwd;
my $pwd = cwd;
@Config::Fast::Define = ([ROOT => $pwd]);
my %conf = fastconfig("$pwd/conf/core.conf");
Each element of
=item %Convert
This is a hash of regex patterns specifying values that should be converted
before being returned. By default, values that look like C<true|on|yes>
will be converted to 1, and values that match C<false|off|no> will be
converted to 0. You could set your own conversions with:
$Config::Fast::CONVERT{'fluffy|chewy'} = 'taffy';
This would convert any settings of "fluffy" or "chewy" to "taffy".
=back
=head1 NOTES
Variables starting with a leading underscore are considered reserved
and should not be used in your config file, unless you enjoy painfully
mysterious behavior.
For a much more full-featured config module, check out C<Config::ApacheFormat>.
It can handle Apache style blocks, array values, etc, etc. This one is
supposed to be fast and easy.
=head1 VERSION
$Id: Fast.pm,v 1.7 2006/03/06 22:18:41 nwiger Exp $
=head1 AUTHOR
Copyright (c) 2002-2005 Nathan Wiger <nate@wiger.org>. All Rights Reserved.
This module is free software; you may copy this under the terms of
the GNU General Public License, or the Artistic License, copies of
which should have accompanied your Perl kit.
=cut
( run in 0.475 second using v1.01-cache-2.11-cpan-71847e10f99 )