mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-16 20:21:01 +01:00
2.43
- fixed rt.cpan.org#40925, $indichar replaced by internal configuration variable EOFseparator, which contains a 256 bit SHA checksum of the date I fixed the bug. This will prevent future conflicts hopefully. In addition it makes it possible to make it customizable, if neccessary, in a future release. - fixed rt.cpan.org#42721, return undef for empty values - fixed rt.cpan.org#42331, return undef for empty objects - fixed rt.cpan.org#44600, comments after blockname causes parser failure. - fixed rt.cpan.org#42287, whitespace at beginning or end of a quoted value gets lost after save(). - fixed rt.cpan.org#46184, variables that were not previously defined are deleted when -InterPolateEnv is enabled. - fixed bug in config loader for FileHandle objects, it supports now any compatible object. Hint by Ingo Schmiegel. - applied spelling- and speedup patches by Ville Skyttä. - applied documentation patch by Jordan Macdonald. git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@69 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
184
General.pm
184
General.pm
@@ -5,7 +5,7 @@
|
||||
# config values from a given file and
|
||||
# return it as hash structure
|
||||
#
|
||||
# Copyright (c) 2000-2008 Thomas Linden <tlinden |AT| cpan.org>.
|
||||
# Copyright (c) 2000-2009 Thomas Linden <tlinden |AT| cpan.org>.
|
||||
# All Rights Reserved. Std. disclaimer applies.
|
||||
# Artificial License, same as perl itself. Have fun.
|
||||
#
|
||||
@@ -32,7 +32,7 @@ use Carp::Heavy;
|
||||
use Carp;
|
||||
use Exporter;
|
||||
|
||||
$Config::General::VERSION = 2.42;
|
||||
$Config::General::VERSION = 2.43;
|
||||
|
||||
use vars qw(@ISA @EXPORT_OK);
|
||||
use base qw(Exporter);
|
||||
@@ -47,6 +47,11 @@ sub new {
|
||||
|
||||
# define default options
|
||||
my $self = {
|
||||
# sha256 of current date
|
||||
# hopefully this lowers the probability that
|
||||
# this matches any configuration key or value out there
|
||||
# bugfix for rt.40925
|
||||
EOFseparator => 'ad7d7b87f5b81d2a0d5cb75294afeb91aa4801b1f8e8532dc1b633c0e1d47037',
|
||||
SlashIsDirectory => 0,
|
||||
AllowMultiOptions => 1,
|
||||
MergeDuplicateOptions => 0,
|
||||
@@ -150,7 +155,8 @@ sub _process {
|
||||
croak "Config::General: Parameter -ConfigHash must be a hash reference!\n";
|
||||
}
|
||||
}
|
||||
elsif (ref($self->{ConfigFile}) eq 'GLOB' || ref($self->{ConfigFile}) eq 'FileHandle') {
|
||||
# elsif (ref($self->{ConfigFile}) eq 'GLOB' || ref($self->{ConfigFile}) eq 'FileHandle') {
|
||||
elsif (ref($self->{ConfigFile})) {
|
||||
# use the file the glob points to
|
||||
$self->_read($self->{ConfigFile});
|
||||
$self->{config} = $self->_parse($self->{DefaultConfig}, $self->{content});
|
||||
@@ -453,7 +459,7 @@ sub _open {
|
||||
}
|
||||
if (!$found) {
|
||||
my $path_message = defined $this->{ConfigPath} ? q( within ConfigPath: ) . join(q(.), @{$this->{ConfigPath}}) : q();
|
||||
croak qq{Config::GeneralThe file "$basefile" does not exist$path_message!};
|
||||
croak qq{Config::General The file "$basefile" does not exist$path_message!};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,7 +587,7 @@ sub _read {
|
||||
# inside here-doc, only look for $hierend marker
|
||||
if (/^(\s*)\Q$hierend\E\s*$/) {
|
||||
my $indent = $1; # preserve indentation
|
||||
$hier .= ' ' . chr 182; # append a "<22>" to the here-doc-name, so
|
||||
$hier .= ' ' . $this->{EOFseparator}; # bugfix of rt.40925
|
||||
# _parse will also preserver indentation
|
||||
if ($indent) {
|
||||
foreach (@hierdoc) {
|
||||
@@ -609,7 +615,7 @@ sub _read {
|
||||
##
|
||||
|
||||
# Remove comments and empty lines
|
||||
s/(?<!\\)#.+$//;
|
||||
s/(?<!\\)#.*$//; # .+ => .* bugfix rt.cpan.org#44600
|
||||
next if /^\s*#/;
|
||||
next if /^\s*$/;
|
||||
|
||||
@@ -754,21 +760,20 @@ sub _parse {
|
||||
my($this, $config, $content) = @_;
|
||||
my(@newcontent, $block, $blockname, $chunk,$block_level);
|
||||
local $_;
|
||||
my $indichar = chr 182; # <20>, inserted by _open, our here-doc indicator
|
||||
|
||||
foreach (@{$content}) { # loop over content stack
|
||||
chomp;
|
||||
$chunk++;
|
||||
$_ =~ s/^\s*//; # strip spaces @ end and begin
|
||||
$_ =~ s/\s*$//;
|
||||
$_ =~ s/^\s+//; # strip spaces @ end and begin
|
||||
$_ =~ s/\s+$//;
|
||||
|
||||
#
|
||||
# build option value assignment, split current input
|
||||
# using whitespace, equal sign or optionally here-doc
|
||||
# separator (ascii 182).
|
||||
# separator EOFseparator
|
||||
my ($option,$value);
|
||||
if (/$indichar/) {
|
||||
($option,$value) = split /\s*$indichar\s*/, $_, 2; # separated by heredoc-finding in _open()
|
||||
if (/$this->{EOFseparator}/) {
|
||||
($option,$value) = split /\s*$this->{EOFseparator}\s*/, $_, 2; # separated by heredoc-finding in _open()
|
||||
}
|
||||
else {
|
||||
if ($this->{SplitPolicy} eq 'guess') {
|
||||
@@ -1020,8 +1025,8 @@ sub _copy {
|
||||
# fixes rt.cpan.org bug #35122
|
||||
my($this, $source) = @_;
|
||||
my %hash = ();
|
||||
foreach my $key (keys %{$source}) {
|
||||
$hash{$key} = $source->{$key};
|
||||
while (my ($key, $value) = each %{$source}) {
|
||||
$hash{$key} = $value;
|
||||
}
|
||||
return \%hash;
|
||||
}
|
||||
@@ -1037,7 +1042,7 @@ sub _parse_value {
|
||||
|
||||
# avoid "Use of uninitialized value"
|
||||
if (! defined $value) {
|
||||
$value = q();
|
||||
$value = undef; # bigfix rt.cpan.org#42721 q();
|
||||
}
|
||||
|
||||
if ($this->{InterPolateVars}) {
|
||||
@@ -1083,7 +1088,7 @@ sub NoMultiOptions {
|
||||
# Since we do parsing from within new(), we must
|
||||
# call it again if one turns NoMultiOptions on!
|
||||
#
|
||||
croak q(Config::GeneralThe NoMultiOptions() method is deprecated. Set 'AllowMultiOptions' to 'no' instead!);
|
||||
croak q(Config::Genera: lThe NoMultiOptions() method is deprecated. Set 'AllowMultiOptions' to 'no' instead!);
|
||||
}
|
||||
|
||||
|
||||
@@ -1103,7 +1108,7 @@ sub save {
|
||||
$this->save_file($one, \%h);
|
||||
}
|
||||
else {
|
||||
croak q(Config::GeneralThe save() method is deprecated. Use the new save_file() method instead!);
|
||||
croak q(Config::General: The save() method is deprecated. Use the new save_file() method instead!);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1272,6 +1277,11 @@ sub _write_scalar {
|
||||
else {
|
||||
# a simple stupid scalar entry
|
||||
$line =~ s/#/\\#/g;
|
||||
# bugfix rt.cpan.org#42287
|
||||
if ($line =~ /^\s/ or $line =~ /\s$/) {
|
||||
# need to quote it
|
||||
$line = "\"$line\"";
|
||||
}
|
||||
$config_string .= $indent . $entry . $this->{StoreDelimiter} . $line . "\n";
|
||||
}
|
||||
|
||||
@@ -1306,14 +1316,12 @@ sub _hashref {
|
||||
# return a probably tied new empty hash ref
|
||||
#
|
||||
my($this) = @_;
|
||||
my ($package, $filename, $line, $subroutine, $hasargs,
|
||||
$wantarray, $evaltext, $is_require, $hints, $bitmask) = caller 0;
|
||||
if ($this->{Tie}) {
|
||||
eval {
|
||||
eval qq{require $this->{Tie}};
|
||||
};
|
||||
if ($EVAL_ERROR) {
|
||||
croak q(Config::GeneralCould not create a tied hash of type: ) . $this->{Tie} . q(: ) . $EVAL_ERROR;
|
||||
croak q(Config::General: Could not create a tied hash of type: ) . $this->{Tie} . q(: ) . $EVAL_ERROR;
|
||||
}
|
||||
my %hash;
|
||||
tie %hash, $this->{Tie};
|
||||
@@ -1343,11 +1351,11 @@ sub SaveConfig {
|
||||
my ($file, $hash) = @_;
|
||||
|
||||
if (!$file || !$hash) {
|
||||
croak q{Config::GeneralSaveConfig(): filename and hash argument required.};
|
||||
croak q{Config::General::SaveConfig(): filename and hash argument required.};
|
||||
}
|
||||
else {
|
||||
if (ref($hash) ne 'HASH') {
|
||||
croak q(Config::GeneralThe second parameter must be a reference to a hash!);
|
||||
croak q(Config::General::SaveConfig() The second parameter must be a reference to a hash!);
|
||||
}
|
||||
else {
|
||||
(new Config::General(-ConfigHash => $hash))->save_file($file);
|
||||
@@ -1364,11 +1372,11 @@ sub SaveConfigString {
|
||||
my ($hash) = @_;
|
||||
|
||||
if (!$hash) {
|
||||
croak q{Config::GeneralSaveConfigString(): Hash argument required.};
|
||||
croak q{Config::General::SaveConfigString(): Hash argument required.};
|
||||
}
|
||||
else {
|
||||
if (ref($hash) ne 'HASH') {
|
||||
croak q(Config::GeneralThe parameter must be a reference to a hash!);
|
||||
croak q(Config::General::SaveConfigString() The parameter must be a reference to a hash!);
|
||||
}
|
||||
else {
|
||||
return (new Config::General(-ConfigHash => $hash))->save_string();
|
||||
@@ -1406,15 +1414,15 @@ Config::General - Generic Config Module
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module opens a config file and parses it's contents for you. The B<new> method
|
||||
This module opens a config file and parses its contents for you. The B<new> method
|
||||
requires one parameter which needs to be a filename. The method B<getall> returns a hash
|
||||
which contains all options and it's associated values of your config file.
|
||||
which contains all options and its associated values of your config file.
|
||||
|
||||
The format of config files supported by B<Config::General> is inspired by the well known apache config
|
||||
format, in fact, this module is 100% compatible to apache configs, but you can also just use simple
|
||||
name/value pairs in your config files.
|
||||
The format of config files supported by B<Config::General> is inspired by the well known Apache config
|
||||
format, in fact, this module is 100% compatible to Apache configs, but you can also just use simple
|
||||
name/value pairs in your config files.
|
||||
|
||||
In addition to the capabilities of an apache config file it supports some enhancements such as here-documents,
|
||||
In addition to the capabilities of an Apache config file it supports some enhancements such as here-documents,
|
||||
C-style comments or multiline options.
|
||||
|
||||
|
||||
@@ -1487,7 +1495,7 @@ If the value is "no", then multiple identical options are disallowed.
|
||||
The default is "yes".
|
||||
i.e.:
|
||||
|
||||
-AllowMultiOptions => "no"
|
||||
-AllowMultiOptions => "yes"
|
||||
|
||||
see B<IDENTICAL OPTIONS> for details.
|
||||
|
||||
@@ -1502,7 +1510,7 @@ values of the options will B<not> lowercased.
|
||||
=item B<-UseApacheInclude>
|
||||
|
||||
If set to a true value, the parser will consider "include ..." as valid include
|
||||
statement (just like the well known apache include statement).
|
||||
statement (just like the well known Apache include statement).
|
||||
|
||||
|
||||
|
||||
@@ -1580,7 +1588,7 @@ config hash.
|
||||
|
||||
Setting this option implies B<-AllowMultiOptions == false> unless you set
|
||||
B<-AllowMultiOptions> explicit to 'true'. In this case duplicate blocks are
|
||||
allowed and put into an array but dupclicate options will be merged.
|
||||
allowed and put into an array but duplicate options will be merged.
|
||||
|
||||
|
||||
=item B<-AutoLaunder>
|
||||
@@ -1658,7 +1666,7 @@ The resulting config structure would look like this after parsing:
|
||||
This method allows the user (or, the "maintainer" of the configfile for your
|
||||
application) to set multiple pre-defined values for one option.
|
||||
|
||||
Please beware, that all occurencies of those variables will be handled this
|
||||
Please beware, that all occurrences of those variables will be handled this
|
||||
way, there is no way to distinguish between variables in different scopes.
|
||||
That means, if "Mode" would also occur inside a named block, it would
|
||||
also parsed this way.
|
||||
@@ -1696,10 +1704,10 @@ which allows you to set default values for particular config options directly.
|
||||
B<-Tie> takes the name of a Tie class as argument that each new hash should be
|
||||
based off of.
|
||||
|
||||
This hash will be used as the 'backing hash' instead of a standard perl hash,
|
||||
This hash will be used as the 'backing hash' instead of a standard Perl hash,
|
||||
which allows you to affect the way, variable storing will be done. You could, for
|
||||
example supply a tied hash, say Tie::DxHash, which preserves ordering of the
|
||||
keys in the config (which a standard perl hash won't do). Or, you could supply
|
||||
keys in the config (which a standard Perl hash won't do). Or, you could supply
|
||||
a hash tied to a DBM file to save the parsed variables to disk.
|
||||
|
||||
There are many more things to do in tie-land, see L<tie> to get some interesting
|
||||
@@ -1726,7 +1734,7 @@ Example:
|
||||
=item B<-InterPolateVars>
|
||||
|
||||
If set to a true value, variable interpolation will be done on your config
|
||||
input. See L<Config::General::Interpolated> for more informations.
|
||||
input. See L<Config::General::Interpolated> for more information.
|
||||
|
||||
=item B<-InterPolateEnv>
|
||||
|
||||
@@ -1743,7 +1751,7 @@ access the parsed config. See L<Config::General::Extended> for more informations
|
||||
=item B<-StrictObjects>
|
||||
|
||||
By default this is turned on, which causes Config::General to croak with an
|
||||
error if you try to access a non-existent key using the oop-way (B<-ExtendedAcess>
|
||||
error if you try to access a non-existent key using the OOP-way (B<-ExtendedAcess>
|
||||
enabled). If you turn B<-StrictObjects> off (by setting to 0 or "no") it will
|
||||
just return an empty object/hash/scalar. This is valid for OOP-access 8via AUTOLOAD
|
||||
and for the methods obj(), hash() and value().
|
||||
@@ -1759,10 +1767,10 @@ in a config. Set to I<false> (i.e. 0) to avoid such error messages.
|
||||
|
||||
You can influence the way how Config::General decides which part of a line
|
||||
in a config file is the key and which one is the value. By default it tries
|
||||
it's best to guess. That means you can mix equalsign assignments and whitespace
|
||||
its best to guess. That means you can mix equalsign assignments and whitespace
|
||||
assignments.
|
||||
|
||||
However, somtimes you may wish to make it more strictly for some reason. In
|
||||
However, somtime you may wish to make it more strictly for some reason. In
|
||||
this case you can set B<-SplitPolicy>. The possible values are: 'guess' which
|
||||
is the default, 'whitespace' which causes the module to split by whitespace,
|
||||
'equalsign' which causes it to split strictly by equal sign, or 'custom'. In the
|
||||
@@ -1771,12 +1779,12 @@ of your choice. For example:
|
||||
|
||||
-SplitDelimiter => '\s*:\s*'
|
||||
|
||||
will cause the module to split by colon while whitespaces which surrounds
|
||||
will cause the module to split by colon while whitespace which surrounds
|
||||
the delimiter will be removed.
|
||||
|
||||
Please note that the delimiter used when saving a config (save_file() or save_string())
|
||||
will be choosen accordingto the current B<-SplitPolicy>. If -SplitPolicy is
|
||||
set to 'guess' or 'whitespace', 3 whitespaces will be used to delimit saved
|
||||
will be chosen according to the current B<-SplitPolicy>. If -SplitPolicy is
|
||||
set to 'guess' or 'whitespace', 3 spaces will be used to delimit saved
|
||||
options. If 'custom' is set, then you need to set B<-StoreDelimiter>.
|
||||
|
||||
=item B<-SplitDelimiter>
|
||||
@@ -1790,7 +1798,7 @@ You can use this parameter to specify a custom delimiter to use when saving
|
||||
configs to a file or string. You only need to set it if you want to store
|
||||
the config back to disk and if you have B<-SplitPolicy> set to 'custom'.
|
||||
|
||||
Be very carefull with this parameter.
|
||||
Be very careful with this parameter.
|
||||
|
||||
|
||||
=item B<-CComments>
|
||||
@@ -1809,7 +1817,7 @@ character within configurations.
|
||||
|
||||
By default it is turned off.
|
||||
|
||||
Be carefull with this option, as it removes all backslashes after parsing.
|
||||
Be careful with this option, as it removes all backslashes after parsing.
|
||||
|
||||
B<This option might be removed in future versions>.
|
||||
|
||||
@@ -1819,7 +1827,7 @@ If you turn on this parameter, a single slash as the last character
|
||||
of a named block will be considered as a directory name.
|
||||
|
||||
By default this flag is turned off, which makes the module somewhat
|
||||
incompatible to apache configs, since such a setup will be normally
|
||||
incompatible to Apache configs, since such a setup will be normally
|
||||
considered as an explicit empty block, just as XML defines it.
|
||||
|
||||
For example, if you have the following config:
|
||||
@@ -1850,19 +1858,19 @@ However, a raw apache config comes without such quotes. In this
|
||||
case you may consider to turn on B<-SlashIsDirectory>.
|
||||
|
||||
Please note that this is a new option (incorporated in version 2.30),
|
||||
it may lead to various unexpected sideeffects or other failures.
|
||||
it may lead to various unexpected side effects or other failures.
|
||||
You've been warned.
|
||||
|
||||
=item B<-ApacheCompatible>
|
||||
|
||||
Over the past years a lot of options has been incorporated
|
||||
into Config::General to be able to parse real apache configs.
|
||||
into Config::General to be able to parse real Apache configs.
|
||||
|
||||
The new B<-ApacheCompatible> option now makes it possible to
|
||||
tweak all options in a way that apache configs can be parsed.
|
||||
tweak all options in a way that Apache configs can be parsed.
|
||||
|
||||
This is called "apache compatibility mode" - if you will ever
|
||||
have problems with parsing apache configs without this option
|
||||
have problems with parsing Apache configs without this option
|
||||
being set, you'll get no help by me. Thanks :)
|
||||
|
||||
The following options will be set:
|
||||
@@ -1885,7 +1893,7 @@ explicit empty blocks.
|
||||
=item B<-UTF8>
|
||||
|
||||
If turned on, all files will be opened in utf8 mode. This may
|
||||
not work properly with older versions of perl.
|
||||
not work properly with older versions of Perl.
|
||||
|
||||
=item B<-SaveSorted>
|
||||
|
||||
@@ -1907,14 +1915,14 @@ Returns a list of all files read in.
|
||||
|
||||
=item save_file()
|
||||
|
||||
Writes the config hash back to the harddisk. This method takes one or two
|
||||
Writes the config hash back to the hard disk. This method takes one or two
|
||||
parameters. The first parameter must be the filename where the config
|
||||
should be written to. The second parameter is optional, it must be a
|
||||
reference to a hash structure, if you set it. If you do not supply this second parameter
|
||||
then the internal config hash, which has already been parsed, will be
|
||||
used.
|
||||
|
||||
Please note, that any occurence of comments will be ignored by getall()
|
||||
Please note that any occurence of comments will be ignored by getall()
|
||||
and thus be lost after you call this method.
|
||||
|
||||
You need also to know that named blocks will be converted to nested blocks
|
||||
@@ -1965,11 +1973,11 @@ or:
|
||||
|
||||
=head1 CONFIG FILE FORMAT
|
||||
|
||||
Lines begining with B<#> and empty lines will be ignored. (see section COMMENTS!)
|
||||
Spaces at the begining and the end of a line will also be ignored as well as tabulators.
|
||||
If you need spaces at the end or the beginning of a value you can use
|
||||
apostrophs B<">.
|
||||
An optionline starts with it's name followed by a value. An equalsign is optional.
|
||||
Lines beginning with B<#> and empty lines will be ignored. (see section COMMENTS!)
|
||||
Spaces at the beginning and the end of a line will also be ignored as well as tabulators.
|
||||
If you need spaces at the end or the beginning of a value you can surround it with
|
||||
double quotes.
|
||||
An option line starts with its name followed by a value. An equal sign is optional.
|
||||
Some possible examples:
|
||||
|
||||
user max
|
||||
@@ -1985,7 +1993,7 @@ The method B<getall> returns a hash of all values.
|
||||
=head1 BLOCKS
|
||||
|
||||
You can define a B<block> of options. A B<block> looks much like a block
|
||||
in the wellknown apache config format. It starts with E<lt>B<blockname>E<gt> and ends
|
||||
in the wellknown Apache config format. It starts with E<lt>B<blockname>E<gt> and ends
|
||||
with E<lt>/B<blockname>E<gt>. An example:
|
||||
|
||||
<database>
|
||||
@@ -2068,7 +2076,7 @@ As you can see, the keys inside the config hash are normalized.
|
||||
Please note, that the above config block would result in a
|
||||
valid hash structure, even if B<-LowerCaseNames> is not set!
|
||||
This is because I<Config::General> does not
|
||||
use the blocknames to check if a block ends, instead it uses an internal
|
||||
use the block names to check if a block ends, instead it uses an internal
|
||||
state counter, which indicates a block end.
|
||||
|
||||
If the module cannot find an end-block statement, then this block will be ignored.
|
||||
@@ -2078,7 +2086,7 @@ If the module cannot find an end-block statement, then this block will be ignore
|
||||
=head1 NAMED BLOCKS
|
||||
|
||||
If you need multiple blocks of the same name, then you have to name every block.
|
||||
This works much like apache config. If the module finds a named block, it will
|
||||
This works much like Apache config. If the module finds a named block, it will
|
||||
create a hashref with the left part of the named block as the key containing
|
||||
one or more hashrefs with the right part of the block as key containing everything
|
||||
inside the block(which may again be nested!). As examples says more than words:
|
||||
@@ -2111,12 +2119,12 @@ You cannot have more than one named block with the same name because it will
|
||||
be stored in a hashref and therefore be overwritten if a block occurs once more.
|
||||
|
||||
|
||||
=head1 WHITESPACES IN BLOCKS
|
||||
=head1 WHITESPACE IN BLOCKS
|
||||
|
||||
The normal behavior of Config::General is to look for whitespaces in
|
||||
The normal behavior of Config::General is to look for whitespace in
|
||||
block names to decide if it's a named block or just a simple block.
|
||||
|
||||
Sometimes you may need blocknames which have whitespaces in their names.
|
||||
Sometimes you may need blocknames which have whitespace in their names.
|
||||
|
||||
With named blocks this is no problem, as the module only looks for the
|
||||
first whitespace:
|
||||
@@ -2133,7 +2141,7 @@ would be parsed to:
|
||||
}
|
||||
};
|
||||
|
||||
The problem occurs, if you want to have a simple block containing whitespaces:
|
||||
The problem occurs, if you want to have a simple block containing whitespace:
|
||||
|
||||
<hugo gera>
|
||||
</hugo gera>
|
||||
@@ -2148,7 +2156,7 @@ The save() method of the module inserts automatically quotation marks in such
|
||||
cases.
|
||||
|
||||
|
||||
=head1 EXPICIT EMPTY BLOCKS
|
||||
=head1 EXPLICIT EMPTY BLOCKS
|
||||
|
||||
Beside the notation of blocks mentioned above it is possible to use
|
||||
explicit empty blocks.
|
||||
@@ -2177,9 +2185,9 @@ Example:
|
||||
log log2
|
||||
log log2
|
||||
|
||||
You will get a scalar if the option occured only once or an array if it occured
|
||||
You will get a scalar if the option occurred only once or an array if it occurred
|
||||
more than once. If you expect multiple identical options, then you may need to
|
||||
check if an option occured more than once:
|
||||
check if an option occurred more than once:
|
||||
|
||||
$allowed = $hash{jonas}->{tablestructure}->{allowed};
|
||||
if(ref($allowed) eq "ARRAY") {
|
||||
@@ -2224,10 +2232,12 @@ this:
|
||||
|
||||
$VAR1 = {
|
||||
'dir' => {
|
||||
'blah' => [
|
||||
'user' => 'max',
|
||||
'user' => 'hannes'
|
||||
]
|
||||
'blah' => {
|
||||
'user' => [
|
||||
'max',
|
||||
'hannes'
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2238,7 +2248,7 @@ tune merging of duplicate blocks and options independent from each other.
|
||||
|
||||
If you don't want to allow more than one identical options, you may turn it off
|
||||
by setting the flag I<AllowMultiOptions> in the B<new()> method to "no".
|
||||
If turned off, Config::General will complain about multiple occuring options
|
||||
If turned off, Config::General will complain about multiple occurring options
|
||||
with identical names!
|
||||
|
||||
|
||||
@@ -2262,7 +2272,7 @@ command will become:
|
||||
=head1 HERE DOCUMENTS
|
||||
|
||||
You can also define a config value as a so called "here-document". You must tell
|
||||
the module an identifier which identicates the end of a here document. An
|
||||
the module an identifier which idicates the end of a here document. An
|
||||
identifier must follow a "<<".
|
||||
|
||||
Example:
|
||||
@@ -2277,7 +2287,7 @@ Example:
|
||||
Everything between the two "EOF" strings will be in the option I<message>.
|
||||
|
||||
There is a special feature which allows you to use indentation with here documents.
|
||||
You can have any amount of whitespaces or tabulators in front of the end
|
||||
You can have any amount of whitespace or tabulators in front of the end
|
||||
identifier. If the module finds spaces or tabs then it will remove exactly those
|
||||
amount of spaces from every line inside the here-document.
|
||||
|
||||
@@ -2297,7 +2307,7 @@ After parsing, message will become:
|
||||
homedir of
|
||||
root.
|
||||
|
||||
because there were the string " " in front of EOF, which were cutted from every
|
||||
because there were the string " " in front of EOF, which were cut from every
|
||||
line inside the here-document.
|
||||
|
||||
|
||||
@@ -2317,8 +2327,8 @@ statement to include an external file:
|
||||
This file will be inserted at the position where it was found as if the contents of this file
|
||||
were directly at this position.
|
||||
|
||||
You can also recurively include files, so an included file may include another one and so on.
|
||||
Beware that you do not recursively load the same file, you will end with an errormessage like
|
||||
You can also recursively include files, so an included file may include another one and so on.
|
||||
Beware that you do not recursively load the same file, you will end with an error message like
|
||||
"too many open files in system!".
|
||||
|
||||
By default included files with a relative pathname will be opened from within the current
|
||||
@@ -2339,7 +2349,7 @@ In this example Config::General will try to include I<acl.cfg> from I</etc/crypt
|
||||
/etc/crypt.d/acl.cfg
|
||||
|
||||
The default behavior (if B<-IncludeRelative> is B<not> set!) will be to open just I<acl.cfg>,
|
||||
whereever it is, i.e. if you did a chdir("/usr/local/etc"), then Config::General will include:
|
||||
wherever it is, i.e. if you did a chdir("/usr/local/etc"), then Config::General will include:
|
||||
|
||||
/usr/local/etc/acl.cfg
|
||||
|
||||
@@ -2380,7 +2390,7 @@ in this case is undefined.
|
||||
=head1 COMMENTS
|
||||
|
||||
A comment starts with the number sign B<#>, there can be any number of spaces and/or
|
||||
tabstops in front of the #.
|
||||
tab stops in front of the #.
|
||||
|
||||
A comment can also occur after a config statement. Example:
|
||||
|
||||
@@ -2402,7 +2412,7 @@ if the Module finds a B</*> string which is the start of a comment block, but no
|
||||
end block, it will ignore the whole rest of the config file!
|
||||
|
||||
B<NOTE:> If you require the B<#> character (number sign) to remain in the option value, then
|
||||
you can use a backlsash in front of it, to escape it. Example:
|
||||
you can use a backslash in front of it, to escape it. Example:
|
||||
|
||||
bgcolor = \#ffffcc
|
||||
|
||||
@@ -2420,7 +2430,7 @@ supplied with the Config::General distribution.
|
||||
|
||||
=head1 VARIABLE INTERPOLATION
|
||||
|
||||
You can use variables inside your configfiles if you like. To do
|
||||
You can use variables inside your config files if you like. To do
|
||||
that you have to use the module B<Config::General::Interpolated>,
|
||||
which is supplied with the Config::General distribution.
|
||||
|
||||
@@ -2481,7 +2491,7 @@ No environment variables will be used.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
I recommend you to read the following documentations, which are supplied with perl:
|
||||
I recommend you to read the following documents, which are supplied with Perl:
|
||||
|
||||
perlreftut Perl references short introduction
|
||||
perlref Perl references, the rest of the story
|
||||
@@ -2493,7 +2503,7 @@ I recommend you to read the following documentations, which are supplied with pe
|
||||
|
||||
=head1 LICENSE AND COPYRIGHT
|
||||
|
||||
Copyright (c) 2000-2007 Thomas Linden
|
||||
Copyright (c) 2000-2009 Thomas Linden
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the same terms as Perl itself.
|
||||
@@ -2508,13 +2518,13 @@ None known.
|
||||
|
||||
=head1 DIAGNOSTICS
|
||||
|
||||
To debug Config::General use the perl debugger, see L<perldebug>.
|
||||
To debug Config::General use the Perl debugger, see L<perldebug>.
|
||||
|
||||
=head1 DEPENDENCIES
|
||||
|
||||
Config::General depends on the modules L<FileHandle>,
|
||||
L<File::Spec::Functions>, L<File::Glob>, which all are
|
||||
shipped with perl.
|
||||
shipped with Perl.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
@@ -2522,7 +2532,7 @@ Thomas Linden <tlinden |AT| cpan.org>
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
2.42
|
||||
2.43
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
Reference in New Issue
Block a user