Advanced-Config
view release on metacpan or search on metacpan
lib/Advanced/Config/Options.pm view on Meta::CPAN
the default behavior for that option. So only override what you need to.
Also all options are in lower case. But you may provide them in mixed case if
you wish. This module will auto downshift them for you.
If an option is misspelled, or you don't provide a valid value, a warning will
be written to the screen and that option will be ignored.
=head1 ==================================================================
=head2 Z<>
=head1 The Read Options
In most cases the defaults should do nicely for you. But when you share config
files between applications, you may not have any control over the config file's
format. This may also apply if your organization requires a specific format
for its config files.
So this section deals with the options you can use to override how it parses and
interprets the config file when it is loaded into memory. None of these options
below allows leading or trailing spaces in the option's value. And if any are
found, they will be automatically trimmed off before their value is used.
Internal spaces are OK when non-numeric values are expected. In most cases
values with a length of B<0> or B<undef> are not allowed.
Just be aware that some combinations of I<Read> options may result in this
module being unable to parse the config file. If you encounter such a
combination open a CPAN ticket and I'll see what I can do about it. But some
combinations may just be too ambiguous to handle.
Also note that some I<Read> options have B<left> and B<right> variants. These
options are used in pairs and both must anchor the target in order for the rule
to be applied to it. These start/end anchors can be set to the same string or
different strings. Your choice.
=head2 Tag(s) Best Set in Call to the Constructor new().
While not required to set these options during the call to B<new>, changing
their settings later on can cause unexpected issues if you are not careful.
But it's still recommended that most I<Read> Options be set during the call to
B<new> to avoid having to keep on resetting them all the time and limit these
later changes to handle exceptions to your defaults.
=over 4
B<tag_case> - Config files are made up of tag/value pairs. This option controls
whether the tags are case sensitive (B<0>, the default) or case insensitive
(B<1>). IE do tags B<ABC> and B<abc> represent the same tag or not? So if set,
all tags are assumed to be in lower case for the get/set methods!
=back
=head2 Generic Read Options
These options are also usually set during the call to B<new>, but setting them
later on doesn't produce strange behavior if you change the settings later on.
=over 4
B<croak> - This controls what happens when a function hits an unexpected error
while parsing the config file. Set to B<0> to return an error code (default),
B<-1> to return an error code and print a warning to your screen, B<1> to call
die and terminate your program.
B<export> - Tells if we should export all tag/value pairs to perl's %ENV hash
or not. The default is B<0> for I<No>. Set to B<1> if you want this to happen.
But if set, it reverses the meaning of the B<export_lbl> option defined later
on.
B<use_utf8> - Defaults to B<0>. Set to B<1> if the config file was created
using utf8 encoding. (IE Unicode or Wide Characters.) Guessing this
setting wrong means the file will be unusable as a config file.
B<disable_quotes> - Defaults to B<0>. Set to B<1> if you want to disallow
the stripping of balanced quotes in your config files.
B<disable_variables> - Defaults to B<0>. Set to B<1> if you want to disable
variable expansion in your config files when they are loaded into memory.
B<disable_variable_modifiers> - Defaults to B<0>. Set to B<1> if you want to
disable this feature. See L<http://wiki.bash-hackers.org/syntax/pe> for more
details. This feature allows you to put logic into your config files via
your variable definitions. Automatically disabled when variables are
disabled. Useful when you put a lot of special chars into your variable
names.
B<disable_decryption> - Defaults to B<0>. Set to B<1> if you want to disable
decrypting values that have been marked as encrypted. If a variable references
an encrypted value while disable_decription is active, that variable isn't
expanded.
=cut
# B<enable_backquotes> - Defaults to B<0>. Set to B<1> if you want to enable
# this feature. It's disabled by default since it can be considered a security
# hole if an unauthorized user can modify your config file or your code.
=pod
B<trap_recursion> - Defaults to B<0>. Set to B<1> if you want to treat
recursion as a fatal error when loading a config file. By default it just
ignores the recursion request to prevent infinite loops.
B<source_cb_opts> - A work area for holding values between calls to the
callback function. This is expected to be a hash reference to provide any
needed configuration values needed to parse the next config file. This way
you can avoid global variables. Defaults to an empty hash reference.
B<source_cb> - An optional callback routine called each time your config file
sources in another config file. It's main use is when the I<Read Options>
and/or I<Date Format Options> required to parse each config file change between
files. It's automatically called right before the sourced in file is opened up
for parsing.
Once the new file is sourced in, it inherits most of the options currently used
unless you override them. The only ones not inherited deal with decryption.
Here is the callback function's expected definition:
my ($rOpts, $dOpts) = source_callback_func ($file[, $cbOpts]);
$file --> The file being sourced in.
$cbOpts --> A hash reference containing values needed by your callback
function to decide what options are required to source in the
requested file. You may update the contents of this hash to
preserve info between calls. This module will "never" examine
the contents of this hash!
$rOpts --> A reference to the "Read Options" hash used to parse the file
you want to source in. Returns "undef" if the options don't
change. The returned options override what's currently in use by
"load_config" when loading the current file.
$dOpts --> A reference to the "Date Formatting Options" hash used to tell how
to format the special date variables. Returns "undef" if the
options don't change. The returned options override what's
currently in use by "load_config" when loading the current file.
=back
=head2 Parse Read Options
These options deal with how to parse the config file itself. All values are
literal values. No regular expressions are supported. If you don't want to
allow a particular option to be supported in your config file, and there is
no disable option, feel free to set it to some unlikely long string of
characters that will never match anything in your config files. Such as
"#"x100. (A string of 100 #'s.)
=over 4
B<assign> - Defaults to B<=>. You may use this option to override what string
of characters make up the assignment operator. It's used to split a line
into a tag/value pair. If you want the special case of no separator, IE the
first space separates a tag/value pair, try setting it to B<\\s> since the
interface doesn't allow whitespace as a value.
B<comment> - Defaults to B<#>. This is the comment symbol used when parsing
your config file and everything after it is ignored in most cases. The first
case is when it appears between balanced quotes as part of a tag's value, it's
lib/Advanced/Config/Options.pm view on Meta::CPAN
DBUG_ENTER_FUNC ( $tag, $skip_fish, @_ );
return DBUG_RETURN ( $sensitive );
}
return ( $sensitive );
}
# ==============================================================
=item make_it_sensitive ( @patterns )
Add these pattern(s) to the internal list of patterns that this module considers
sensitive. Should any tag contain this pattern, that tag's value will be
masked when written to this module's internal logs. Leading/trailing spaces
will be ignored in the pattern. Wild cards are not honored.
The 3 default patterns are password, pass, and pwd.
This pattern affects all L<Advanced::Config> objects loaded into memory. Not
just the current one.
=cut
sub make_it_sensitive
{
DBUG_ENTER_FUNC ( @_ );
my @tags = @_;
foreach my $tag ( @tags ) {
if ( $tag ) {
$tag =~ s/^\s+//;
$tag =~ s/\s+$//;
if ( $tag ) {
$tag = convert_to_regexp_string ( $tag, 1 );
push ( @hide_from_fish, $tag );
}
}
}
DBUG_VOID_RETURN ();
}
# ==============================================================
=item $cnt = sensitive_cnt ( )
Returns a count of how many sensitive patterns are being used.
=cut
sub sensitive_cnt
{
DBUG_ENTER_FUNC ( @_ );
DBUG_RETURN ( scalar (@hide_from_fish) );
}
# ==============================================================
=item @ret = croak_helper ($opts, $croak_message, @croak_return_vals)
This helper method helps standardizes what to do on fatal errors when reading
the config file or what to do if you can't find the tag on lookups.
It knows I<\%opts> is a "Read" option hash if B<croak> is a member and it's
a "Get" option hash if B<required> is a member. Both options use the same
logic when called.
See B<croak> and B<required> on what these options do.
Returns whatever I<@croak_return_vals> references. It may be a single value or
an array of values.
It calls B<warn> or B<die> with the message passed.
=cut
# ==============================================================
# No ENTER/RETURN fish calls on purpose here ...
sub croak_helper
{
my $opts = shift;
my $msg = shift;
my @ret = @_; # Use whatever was passed to me ...
# Look up the needed value in the hash we'd like to test out.
my $croak = 0;
if ( exists $opts->{croak} ) {
$croak = $opts->{croak}; # From the Read Opt Hash ...
} elsif ( exists $opts->{required} ) {
$croak = $opts->{required}; # From the Get Opt Hash ...
}
if ( $croak > 0 ) {
die ($msg, "\n");
# The -9876 value is undocumented where we don't even want the msg in fish!
} elsif ( $croak == -9876 ) {
;
} elsif ( $croak < 0 ) {
warn ($msg, "\n");
} else {
DBUG_PRINT ("WARN", $msg);
}
return ( wantarray ? @ret : $ret[0] );
}
# ==============================================================
=item $lvl = set_special_date_vars ( $date_opts_ref, $date_hash_ref[, $old_hash_ref] )
The I<$date_opts_ref> contains the special date variable formatting options
used to control the formattiong of the data returned via I<$date_hash_ref>.
The relevant tags are: I<date_order>, I<date_sep>, I<month_type>, I<use_gmt>
and I<month_language>. Any missing hash key and it's default is used.
This function populates the following date keys in I<$date_hash_ref> for use
by the config object using the current date/time. These keys are also defined
( run in 1.040 second using v1.01-cache-2.11-cpan-13bb782fe5a )