NAME

Aion::Env - creates a constant associated with the value from .env

VERSION

0.1

SYNOPSIS

.env file:

BIN_TEST=10
OCT_TEST=${BIN_TEST}20



BEGIN {
	delete @ENV{qw/BIN_TEST OCT_TEST BB_TEST NN_TEST/};

	$ENV{UNI_TEST} = 30;
}

sub Int { sub { /^-?\d+$/ } }

use Aion::Env BIN_TEST => (isa => Int);
use Aion::Env OCT_TEST => (isa => Int);
use Aion::Env UNI_TEST => (isa => Int);
use Aion::Env BB_TEST => (isa => Int, default => 1);

BIN_TEST; # -> 10
OCT_TEST; # -> 1020
UNI_TEST; # -> 30
BB_TEST; # -> 1

eval 'use Aion::Env NN_TEST => ()'; $@; # ^-> NN_TEST is'nt defined!
eval 'use Aion::Env NN_TEST => (nouname => 1)'; $@; # ^-> Unknown keyword: nouname
eval 'use Aion::Env NN_TEST => (nouname1 => 1, nouname2 => 2)'; $@; # ^-> Unknown keywords: nouname1, nouname2

DESCRIPTION

Projects use the .env configuration file for project configuration, in Makefile, for docker and docker compose. This module allows you to design environment variables as constants of perl modules.

Constants are initialized from %ENV, if there is no value there or it is undef, then from the .env file, and if it is not there, from the default option.

When parsing a file, a syntax error will result in an exception.

The type of an environment variable can be checked using the isa option. It accepts a subroutine or object with the ${} operator overloaded. In this case, the value will be passed to $_. If the object has a validate method, like Aion::Type, then it will be called with parameters: the value and name of the environment variable.

It is recommended to name environment variables using the name of the module in which it is declared. For example, the package is Aion::Type, then the names of the environment variables in it are AION_TYPE_*.

SUBROUTINES

import ($cls, $name, %kw)

Creates a constant with the name $name in the package from which it is called. Optionally, you can pass isa and default to %kw.

parse ($file)

Parses a file in .env format and returns a hash with variables from it.

AUTHOR

Yaroslav O. Kosmina mailto:dart@cpan.org

LICENSE

Perl5

COPYRIGHT

The Aion::Env module is copyright © 2026 Yaroslav O. Kosmina. Rusland. All rights reserved.