Acrux
view release on metacpan or search on metacpan
lib/Acrux/Config.pm view on Meta::CPAN
The module works with the configuration using L<Config::General>
All getters of this class are allows get access to configuration parameters by path-pointers.
See L<Acrux::Pointer> and L<RFC 6901|https://tools.ietf.org/html/rfc6901>
=head2 new
my $config = Acrux::Config->new(
file => '/etc/myapp.conf',
default => {foo => 'bar'},
);
=head1 ATTRIBUTES
This plugin supports the following attributes
=head2 default
default => {foo => 'bar'}
Default configuration data
=head2 dirs
dirs => ['/etc/foo', '/etc/bar']
Paths to additional directories of config files
=head2 file
file => '/etc/foo.stuff'
Path to configuration file, absolute or relative, defaults to the value of the
C<$0.conf> in the current directory
=head2 noload
noload => 1
This attribute disables loading config file
=head2 options
options => {'-AutoTrue' => 0}
Sets the L<Config::General> options directly
=head2 root
root => '/etc/myapp'
Sets the root directory to configuration files and directories location
=head1 METHODS
This plugin implements the following methods
=head2 array, list
dumper $config->array('/foo'); # ['first', 'second', 'third']
# ['first', 'second', 'third']
dumper $config->array('/foo'); # 'value'
# ['value']
Returns an array of found values from configuration
=head2 config, conf
my $config_hash = $config->config; # { ... }
This method returns config structure directly as hash ref
=head2 error
my $error = $config->error;
Returns error string if occurred any errors while creating the object or reading the configuration file
=head2 first
say $config->first('/foo'); # ['first', 'second', 'third']
# first
Returns an first value of found values from configuration
=head2 get
say $config->get('/datadir');
Returns configuration value by path
=head2 hash, object
dumper $config->hash('/foo'); # { foo => 'first', bar => 'second' }
# { foo => 'first', bar => 'second' }
Returns an hash of found values from configuration
=head2 latest
say $config->latest('/foo'); # ['first', 'second', 'third']
# third
Returns an latest value of found values from configuration
=head2 load
my $config = $config->load;
Loading config files
=head2 pointer
my $pointer = $config->pointer;
Returns current L<Acrux::Pointer> object
=head1 HISTORY
See C<Changes> file
=head1 TO DO
See C<TODO> file
=head1 SEE ALSO
L<Config::General>, L<Acrux::Pointer>
=head1 AUTHOR
Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 1998-2026 D&D Corporation
=head1 LICENSE
This program is distributed under the terms of the Artistic License Version 2.0
See the C<LICENSE> file or L<https://opensource.org/license/artistic-2-0> for details
=cut
use Config::General qw//;
use Cwd qw/getcwd/;
use File::Spec qw//;
use File::Basename qw/basename/;
use Acrux::Pointer;
use Acrux::RefUtil qw/as_array is_array_ref is_hash_ref is_value/;
use Acrux::Util qw/clone/;
use constant DEFAULT_CG_OPTS => {
'-ApacheCompatible' => 1, # Makes possible to tweak all options in a way that Apache configs can be parsed
'-LowerCaseNames' => 1, # All options found in the config will be converted to lowercase
'-UTF8' => 1, # All files will be opened in utf8 mode
'-AutoTrue' => 1, # All options in your config file, whose values are set to true or false values, will be normalised to 1 or 0 respectively
};
sub new {
( run in 0.745 second using v1.01-cache-2.11-cpan-39bf76dae61 )