Skip to content

mikkoi/env-assert

License: Artistic-2.0 CPAN Version kwalitee codecov Coverage Status Ask DeepWiki GH Actions: Linux Build GH Actions: Windows Build

Env-Assert

Ensure that the environment variables match what is requested, or abort. Module and executable.

VERSION

version 0.016

SYNOPSIS

use Env::Assert 'assert';
# or:
use Env::Assert assert => {
    envdesc_file => 'another-envdesc',
    break_at_first_error => 1,
};

# .envdesc file:
# MY_VAR=.+

# use any verified environment variable
say $ENV{MY_VAR};

# You can inline the envdesc file:
use Env::Assert assert => {
    exact => 1,
    envdesc => <<'EOF'
NUMERIC_VAR=^[[:digit:]]+$
TIME_VAR=^\d{2}:\d{2}:\d{2}$
EOF
};

DESCRIPTION

envassert checks that your runtime environment, as defined with environment variables, matches with what you want.

You can define your required environment in a file. Default file is .envassert but you can use any file.

It is advantageous to use envassert for example when running a container. If you check your environment for missing or wrongly defined environment variables at the beginning of the container run, your container will fail sooner instead of in a later point in execution when the variables are needed.

Errors

There are three kinds of errors:

  • ENV_ASSERT_MISSING_FROM_ENVIRONMENT

    "Variable <var_name> is missing from environment"

  • ENV_ASSERT_INVALID_CONTENT_IN_VARIABLE

    "Variable <var_name> has invalid content"

  • ENV_ASSERT_MISSING_FROM_DEFINITION

    "Variable <var_name> is missing from description"

    This error will only be reported if you have set the special option exact. See below.

Environment Description Language

Environment is described in file .envdesc. Environment description file is a Unix shell compatible file, similar to a .env file.

.envdesc Format

In .envdesc file there is only environment variables, comments or empty rows. Example:

# Required env
## envassert (opts: exact=1)
FILENAME=^[[:word:]]{1,}$

Env var name is followed by a regular expression. The regexp is an extended Perl regular expression without quotation marks. One env var and its descriptive regexp use one row.

A comment begins at the beginning of the row and uses the whole row. It start with '#' character.

Two comment characters and the word envassert at the beginning of the row mean this is an envassert meta command. You can specify different environment related options with these commands.

Supported options:

  • exact

    The option exact means that all allowed env variables are described in this file. Any unknown env var causes an error when verifying.

CLI interface without dependencies

The envassert command is also available as self contained executable. You can download it and run it as it is without additional installation of CPAN packages. Of course, you still need Perl, but Perl comes with any normal Linux installation.

This can be convenient if you want to, for instance, include envassert in a docker container build.

curl -LSs -o envassert https://raw.githubusercontent.com/mikkoi/env-assert/main/envassert.self-contained
chmod +x ./envassert

INSTALLATION

Packaging

Packaging status

CLI interface without dependencies

The envassert command is also available as self contained executable. You can download it and run it as it is without additional installation of CPAN packages. Of course, you still need Perl, but Perl comes with any normal Linux installation.

This can be convenient if you want to, for instance, include envassert in a docker container build.

curl -LSs -o envassert https://raw.githubusercontent.com/mikkoi/env-assert/main/envassert.self-contained
chmod +x ./envassert

LICENSE

This software is copyright (c) 2026 by Mikko Koivunalho mikkoi@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Terms of the Perl programming language system itself:

a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License"

The complete licenses are in the files LICENSE-Artistic-2.0 and LICENSE-GPL-3 within this repository. If these files are missing, they can be downloaded from the following urls:

* https://www.gnu.org/licenses/
* https://www.perlfoundation.org/artistic-license-20.html

About

Ensure that the environment variables match what you need, or abort.

Topics

Resources

License

Artistic-2.0, GPL-3.0 licenses found

Licenses found

Artistic-2.0
LICENSE-Artistic-2.0
GPL-3.0
LICENSE-GPL-3

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages