NAME
Aion::Env::Etc - creates a constant associated with a key from configuration files
SYNOPSIS
etc/include.yml file:
includes:
- etc/test.yml
test:
abc: -12
File etc/test.yml:
test:
abc: 100
when@dev:
test:
val: 10
BEGIN { $ENV{APP_ENV} = 'dev' }
sub Int { sub { /^-?\d+$/ } }
use Aion::Env::Etc TEST_ABC => (isa => Int);
use Aion::Env::Etc VAL => (isa => Int, key => 'test.val');
TEST_ABC # -> -12
VAL # -> 10
DESCRIPTION
Parses the configuration file. The path to it is specified by the environment variable AION_ENV_ETC_PATH.
It may contain the includes key with the inclusion of other configuration files, and those with other ones. For simplicity, includes are triggered from the current directory, which should correspond to the project root (this is the convention).
Keys of the form when@ID will overlap with their keys the keys of the configuration file if the ID of them matches APP_ENV.
Hashes in keys, if the keys match in different files, are combined recursively. However, if one of the keys does not have a hash, an exception will be thrown.
SUBROUTINES
import ($name, %kw)
Creates a constant in the package from which it was called.
Valid options:
isa– tester routine orAion::Typeobject for type checking.default– default value.key– key from configuration files. By default, the name of the constant is converted to it (translated to lower case and underscores are replaced with dots).
parse ($path)
Reads and parses a configuration file in yaml format. ${ID} are replaced with values from %ENV, and if not there, then from the .env file. Parses files in include recursively.
merge_hashes ($file, $path, $x, $y)
Concatenates two hashes recursively. If the matching keys do not have hashes, then it throws an error with $file and $path, where $file is the connecting file, and $path is the path from the keys through the dot.
val ($s)
Adds backslashes. Used for escaping environments.
my $escape_string = "\\\"\\'\\\\\\t\\r\\n";
Aion::Env::Etc::val("\"'\\\t\r\n") # -> $escape_string
by_key ($hash, $path)
Get the value by key from the hash.
my ($val, $key_exists) = Aion::Env::Etc::by_key({x => {y => {z => 3}}}, "x.y.z");
$val # -> 3
$key_exists # -> 1
($val, $key_exists) = Aion::Env::Etc::by_key({x => {y => {t => 10}}}, "x.y.z");
$val # -> undef
$key_exists # -> 0
AUTHOR
Yaroslav O. Kosmina mailto:dart@cpan.org
LICENSE
⚖ Perl5
COPYRIGHT
The Aion::Env::Etc module is copyright © 2026 Yaroslav O. Kosmina. Rusland. All rights reserved.