Dancer2...igReader(3)
β¨ 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
π COPYRIGHT AND LICENSE π
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
- fedora 44: perl-Dancer2 2.2.1-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms