Dancer2...igReader(3)

πŸ“¦
version 2.2.1 Β· 3 versions
, in fedora 44

✨ Dancer2::ConfigReader β€” the config reader for your Dancer2 app ✨

okay bestie, welcome to Dancer2::ConfigReader, the lil' legend that handles your Dancer2 App's config πŸ’–

VERSION: version 2.2.1 πŸŽ€


🌸 DESCRIPTION 🌸

So this class gives you a config attribute, and that attribute gets populated by running one or more ConfigReader packages. That's the whole vibe.

The default ConfigReader it uses is Dancer2::ConfigReader::Config::Any. no cap πŸ’…

It also gives you a setting() method, which is meant for externals to read and write config entries. iykyk.

If you're using more than one config reader, their configs get merged in left-to-write order, where the previous config items get overwritten by the subsequent ones. (yes, we said left-to-write, that's literally what the page says, we don't make the rules 😭)

For example β€” say we're running 3 config readers, and the first one returns this:

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

and the second one returns this:

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

then the final config is this:

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

see how the later reader just slides in and overwrites the overlapping bits? ate and left no crumbs πŸ”₯

The default ConfigReader is Dancer2::ConfigReader::Config::Any. (yes, again, it's important okay πŸ™ˆ)


🌈 Configuring the ConfigReaders via DANCER_CONFIG_READERS 🌈

You can control which ConfigReader class (or classes!) get used to create the config, all through the DANCER_CONFIG_READERS environment. main character energy fr fr:

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

If you want several of them, separate them with a comma (,). that's it, that's the whole trick πŸ’…


πŸ¦‹ Bootstrapping the ConfigReaders via "additional_config_readers" πŸ¦‹

If the key additional_config_readers shows up in one in one or more of the configurations that the ConfigReaders provide, it'll get instantiated and added to the list of configurations to merge. so you can, for example, make a basic config.yml that looks like:

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

The default ConfigReader Dancer2::ConfigReader::Config::Any will pick that file up and proceed to instantiate Dancer2::ConfigReader::SQLite with the parameters you provided. obsessed, honestly 🫢

additional_config_readers can take one or a list of reader configurations, and each one 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 the class Dancer2::ConfigReader::Config::Any. go off, build your own ✨:

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 lives in the class Dancer2::ConfigReader::Config::Any. go peek if you want the deep lore πŸ‘‘


πŸ’œ ATTRIBUTES πŸ’œ

  • location β€” the absolute path to the directory where the server started. πŸ“
  • config_location β€” grabs the location from the configuration. it's the same as $object->location.
  • environments_location β€” gets the directory where the environment files are stored. 🌱
  • config β€” returns the whole entire configuration.
🚨 bestie listen: this must not be used directly. instead, use it via the Dancer2::Core::Role::HasConfig role, which manages the configuration after it's been created. don't be the person who uses it directly, be the person who uses the role πŸ’…
  • environment β€” returns the name of the environment.

πŸ‘‘ AUTHOR πŸ‘‘

Dancer Core Developers


This software is copyright (c) 2026 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. πŸ’–


and that's the whole page, bestie! this was brought to you by perl v5.42.3, dated 2026-09-20, straight from the Dancer2::ConfigReader(3) page in the User Contributed Perl Documentation. stay iconic, go configure something πŸŒŸπŸ’…

πŸ“¦ where this page comes from