The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mojolicious::Plugin::ConfigGeneral - Config::General Configuration Plugin for Mojolicious

VERSION

Version 1.02

SYNOPSIS

    use Mojolicious::Plugin::ConfigGeneral;

    # Mojolicious
    my $config = $app->plugin('ConfigGeneral');
    say $config->{foo};

    # Mojolicious::Lite
    my $config = plugin 'ConfigGeneral';
    say $config->{foo};

    # The configuration is available application-wide
    my $config = app->config;
    say $config->{foo};

    # Everything can be customized with options
    my $config = plugin ConfigGeneral => {file => '/etc/myapp.conf'};

DESCRIPTION

Mojolicious::Plugin::ConfigGeneral is a Config::General Configuration Plugin for Mojolicious

OPTIONS

This plugin supports the following options

default

    # Mojolicious::Lite
    plugin ConfigGeneral => {default => {foo => 'bar'}};

Default configuration

file

    # Mojolicious::Lite
    plugin ConfigGeneral => {file => 'myapp.conf'};
    plugin ConfigGeneral => {file => '/etc/foo.stuff'};

Path to configuration file, absolute or relative to the application home directory, defaults to the value of the MOJO_CONFIG environment variable or $moniker.conf in the application home directory.

noload

    plugin ConfigGeneral => {noload => 1};

This option disables loading config file

opts

    # Mojolicious::Lite
    plugin ConfigGeneral => {opts => {'-AutoTrue' => 0}};
    plugin ConfigGeneral => {options => {'-AutoTrue' => 0}};

Sets the Config::General options directly

METHODS

This plugin inherits all methods from Mojolicious::Plugin and implements the following new ones

register

    my $config = $plugin->register(Mojolicious->new);
    my $config = $plugin->register(Mojolicious->new, {file => '/etc/foo.conf'});

Register plugin in Mojolicious application and set configuration.

HELPERS

All helpers of this plugin are allows get access to configuration parameters by path-pointers. See Mojo::JSON::Pointer and RFC 6901

conf->get
    say $self->conf->get('/datadir');

Returns configuration value by path

conf->first
    dumper $self->conf->first('/foo'); # ['first', 'second', 'third']
        # 'first'

Returns an first value of found values from configuration

conf->latest
    dumper $self->conf->latest('/foo'); # ['first', 'second', 'third']
        # 'third'

Returns an latest value of found values from configuration

conf->array, conf->list
    dumper $self->conf->array('/foo'); # ['first', 'second', 'third']
        # ['first', 'second', 'third']
    dumper $self->conf->array('/foo'); # 'value'
        # ['value']

Returns an array of found values from configuration

conf->hash, conf->object
    dumper $self->conf->array('/foo'); # { foo => 'first', bar => 'second' }
        # { foo => 'first', bar => 'second' }

Returns an hash of found values from configuration

HISTORY

See Changes file

TO DO

See TODO file

SEE ALSO

Mojolicious::Plugin::Config, Config::General

AUTHOR

Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>

COPYRIGHT

Copyright (C) 1998-2023 D&D Corporation. All Rights Reserved

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See LICENSE file and https://dev.perl.org/licenses/