Dancer2...ig::Any(3)
π Dancer2::ConfigReader::Config::Any π
okay bestie, welcome to the Dancer2::ConfigReader::Config::Any page β that's the module name, and yes, it's a whole mouthful, we're just gonna roll with it. This is the User Contributed Perl Documentation version, and it's literally the config reader for files. sit with me, we're gonna go through it together π«Ά
β¨ VERSION β¨
version 2.2.1 β fresh, iconic, no notes π
πΈ DESCRIPTION πΈ
so this class is an implementation of Dancer2::Core::Role::ConfigReader, and its whole job β its entire main character purpose β is reading the configuration files of Dancer2. that's it. that's the gig. and it eats every single time π₯
if you want the full picture, go check out Dancer2::Config, it's got the lore.
now here's the fun part, bestie: if you need to add extra functionality to the reading mechanism, you can totally extend this class. the example they give is letting you swap out random chunks of your file config with environmental variables, which is honestly kind of genius. here's how that looks:
package Dancer2::ConfigReader::File::Extended;
use Moo;
use Dancer2::Core::Types;
use Carp 'croak';
extends 'Dancer2::ConfigReader::Config::Any';
has name => (
is => 'ro',
isa => Str,
lazy => 0,
default => sub {'File::Extended'},
);
around read_config => sub {
my ($orig, $self) = @_;
my $config = $orig->($self, @_);
$self->_replace_env_vars($config);
return $config;
};
# Attn. We are traversing along the original data structure all the time,
# using references, and changing values on the spot, not returning anything.
sub _replace_env_vars {
my ( $self, $entry ) = @_;
if( ref $entry ne 'HASH' && ref $entry ne 'ARRAY' ) {
croak 'Param entry is not HASH or ARRAY';
}
if( ref $entry eq 'HASH' ) {
foreach my $value (values %{ $entry }) {
if( (ref $value) =~ m/(HASH|ARRAY)/msx ) {
$self->_replace_env_vars( $value );
} elsif( (ref $value) =~ m/(CODE|REF|GLOB)/msx ) {
# Pretty much anything else except SCALAR. Do nothing
1;
} else {
if( $value ) {
while( my ($k, $v) = each %ENV) {
$value =~ s/ \$ [{] ENV:$k [}] /$v/gmsx;
}
}
}
}
} else {
# ref $entry is 'ARRAY'
foreach my $value (@{ $entry }) {
if( (ref $value) =~ m/(HASH|ARRAY)/msx ) {
$self->_replace_env_vars( $value );
} elsif( (ref $value) =~ m/(CODE|REF|GLOB)/msx ) {
# Pretty much anything else except SCALAR. Do nothing
1;
} else {
if( $value ) {
while( my ($k, $v) = each %ENV) {
$value =~ s/ \$ [{] ENV:$k [}] /$v/gmsx;
}
}
}
}
}
return;
}
1;
like. look at that. we're modifying the original data structure in place, we're not returning anything, it's giving very much "I do what I want" energy π
π ATTRIBUTES π
name
the name of the Config Reader class: Config::Any. simple. elegant. slay.
location
absolute path to the directory where the server started. yep, the whole absolute path, no shortcuts π¦
config_location
gets the location from the configuration. same as $object->location. literally the same thing, it's twins.
environments_location
gets the directory where the environment files are stored.
environment
returns the name of the environment. that's it. that's the whole vibe.
config_files
list of all the configuration files. all of them. every last one π
π METHODS π
read_config
load the configuration files. the whole point of the module, honestly. the moment we've all been waiting for β¨
π AUTHOR π
Dancer Core Developers β legends, every single one of them.
π 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. free software bestie, we love to see it π«Ά
and that's the page, babe π this was Dancer2::ConfigReader::Config::Any, documented for perl v5.42.3, dated 2026-09-20 β go forth, read those config files, and be iconic β¨πΈ
π¦ 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