Dancer2::ConfigReader(3)

NAME
Dancer2::ConfigReader - Config reader for Dancer2 App

VERSION
version 2.0.1

DESCRIPTION
This class provides a "config" attribute which is populated by executing one or more ConfigReader packages.

The default ConfigReader used is Dancer2::ConfigReader::Config::Any.

Also provides a setting() method which is supposed to be used by externals to read/write config entries.

If more than one config reader is used, their configurations are merged in left-to-write order where the previous config items get overwritten by subsequent ones.

For example, assuming we are using 3 config readers, if the first config reader returns

    item1: content1
    item2: content2
    item3:
        subitem1: subcontent1
        subitem2: subcontent2
        subitem3:
            subsubitem1:
                subsubcontent1
    item4:
        subitem1: subcontent1
        subitem2: subcontent2

and the second returns

    item2: content9
    item3:
        subitem2: subcontent8
        subitem3:
            subsubitem1:
                subsubcontent7
        subitem4:
            subsubitem5: subsubcontent5
    item4: content4

then the final config is

    item1: content1
    item2: content9
    item3:
        subitem1: subcontent1
        subitem2: subcontent8
        subitem3:
            subsubitem1:
                subsubcontent7
        subitem4:
            subsubitem5: subsubcontent5
    item4: content4

The default ConfigReader is "Dancer2::ConfigReader::Config::Any".

  Configuring the ConfigReaders via DANCER_CONFIG_READERS
You can control which ConfigReader class or classes to use to create the config via the "DANCER_CONFIG_READERS" environment.

    DANCER_CONFIG_READERS='Dancer2::ConfigReader::Config::Any,Dancer2::ConfigReader::CustomConfig'

If you want several, separate them with a comma (",").

  Bootstrapping the ConfigReaders via "additional_config_readers"
If the key "additional_config_readers" is found in one in one or more of the configurations provided by the ConfigReaders, it'll be instantiated and added to the list of configurations to merge. This way you can, for example, create a basic config.yml that is

    additional_config_readers:
        - Dancer2::ConfigReader::SQLite:
            path: /path/to/sqlite.db
            table: config

The default ConfigReader Dancer2::ConfigReader::Config::Any will pick that file and proceed to instantiate "Dancer2::ConfigReader::SQLite" with the provided parameters.

"additional_config_readers" can take one or a list of reader configurations, which can be either the name of the ConfigReader's class, or the key/value pair of the class name and its constructor's arguments.

  Creating your own custom ConfigReader classes.
Here's an example extending class "Dancer2::ConfigReader::Config::Any".

    package Dancer2::ConfigReader::FileExtended;
    use Moo;
    extends 'Dancer2::ConfigReader::Config::Any';
    has name => (
        is      => 'ro',
        default => sub {'FileExtended'},
    );
    around read_config => sub {
        my ($orig, $self) = @_;
        my $config = $orig->($self, @_);
        $config->{'dummy'}->{'item'} = 123;
        return $config;
    };

Another (more complex) example is in class "Dancer2::ConfigReader::Config::Any".

ATTRIBUTES

  location
Absolute path to the directory where the server started.

  config_location
Gets the location from the configuration. Same as "$object->location".

  environments_location
Gets the directory where the environment files are stored.

  config
Returns the whole configuration. This must not be used directly. Instead, use this via "Dancer2::Core::Role::HasConfig" role which manages configuration after it is created.

  environment
Returns the name of the environment.

AUTHOR
Dancer Core Developers

COPYRIGHT AND LICENSE
This software is copyright (c) 2025 by Alexis Sukrieh.

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