Acrux
view release on metacpan or search on metacpan
lib/Acme/Crux/Plugin/Config.pm view on Meta::CPAN
=head1 SEE ALSO
L<Acme::Crux::Plugin>, L<Acrux::Config>
=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 parent 'Acme::Crux::Plugin';
use Acrux::Config;
use Acrux::RefUtil qw/as_array_ref as_hash_ref is_true_flag/;
sub register {
my ($self, $app, $args) = @_;
# NoLoad flag: PLGARGS || OPTS || ORIG || DEFS
my $noload = is_true_flag($args->{noload}) # From plugin arguments first
|| $app->getopt("noload") # From command line options
|| $app->orig->{"config_noload"} # From App arguments
|| 0;
# Config file: PLGARGS || OPTS || ORIG || DEFS
my $file = $args->{file} || $app->getopt("configfile") || $app->configfile;
# Config::General Options: PLGARGS || DEFS
my $options = as_hash_ref($args->{options} || $args->{opts});
# Merge defaults
my $defaults = as_hash_ref($args->{defaults} || $args->{default}) || {};
# Config root dir: PLGARGS || OPTS || ORIG || DEFS
my $root = $args->{root} || $app->getopt("config_root") || $app->getopt("configroot") || $app->root;
# Additional config directories: PLGARGS || DEFS
my $dirs = as_array_ref($args->{dirs});
# Create instance
my $config = Acrux::Config->new(
file => $file,
options => $options,
noload => $noload,
defaults => $defaults,
root => $root,
dirs => $dirs,
);
if (my $err = $config->error) {
if ($app->debugmode) {
$app->verbosemode
? warn qq{Can't load configuration file "$file"\n$err\n}
: warn qq{Can't load configuration file "$file"\n};
}
}
# Set conf and config helpers (methods)
$app->register_method(config => sub { $config });
$app->register_method(conf => sub { $config });
return $config;
}
1;
__END__
( run in 3.088 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )