#!/usr/bin/env perl # This chunk of stuff was generated by App::FatPacker. To find the original # file's code, look for the end of this BEGIN block or the string 'FATPACK' BEGIN { my %fatpacked; $fatpacked{"Env/Dot.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ENV_DOT'; ## no critic (ValuesAndExpressions::ProhibitConstantPragma) package Env::Dot; use strict; use warnings; # We define our own import routine because # this is the point (when `use Env::Dot` is called) # when we do our magic. { no warnings 'redefine'; ## no critic [TestingAndDebugging::ProhibitNoWarnings] sub import { load_vars(); return; } } use English qw( -no_match_vars ); # Avoids regex performance penalty in perl 5.18 and earlier use Carp; # ABSTRACT: Read environment variables from .env file our $VERSION = '0.018'; use Env::Dot::Functions qw( get_dotenv_vars interpret_dotenv_filepath_var get_envdot_filepaths_var_name extract_error_msg create_error_msg ); use constant { OPTION_FILE_TYPE => q{file:type}, OPTION_FILE_TYPE_PLAIN => q{plain}, OPTION_FILE_TYPE_SHELL => q{shell}, DEFAULT_OPTION_FILE_TYPE => q{shell}, DEFAULT_ENVDOT_FILEPATHS => q{.env}, INDENT => q{ }, }; =pod =begin stopwords dotenv env envdot =end stopwords =head1 STATUS This module is currently being developed so changes in the API are possible, though not likely. =head1 SYNOPSIS use Env::Dot; print $ENV{'VAR_DEFINED_IN_DOTENV_FILE'}; =head1 DESCRIPTION More flexibility in how you manage and use your F<.env> file. B A dotenv variable (variable from a file) does not overwrite an existing environment variable. This is by design because a dotenv file is to augment the environment, not to replace it. This means that you can override a variable in `.env` file by creating its counterpart in the environment. For instance: unset VAR echo "VAR='Good value'" >> .env perl -e 'use Env::Dot; print "VAR:$ENV{VAR}\n";' # VAR:Good value VAR='Better value'; export VAR perl -e 'use Env::Dot; print "VAR:$ENV{VAR}\n";' # VAR:Better value =head2 Features =over 8 =item If no B<.env> file is present, then do nothing By default, Env::Dot will do nothing if there is no B<.env> file. You can also configure Env::Dot to emit an alarm or break execution, if you want. =item Specify other dotenv files with path If your B<.env> file is located in another path, not the current working directory, you can use the environment variable B to tell where your dotenv file is located. You can specify several file paths; just separate them by B<:>. Env::Dot will load the files in the B, starting from the last. This is the same ordering as used in B variable: the first overrules the following ones, that is, when reading from the last path to the first path, if same variable is present in more than one file, the later one replaces the one already read. Attn. If you are using Windows, separate the paths by <;>! For example, if you have the following directory structure: project-root | .env + - sub-project | .env and you specify B, then the variables in file B will get replaced by the more specific variables in B. In Windows, this would be B N.B. The ordering has changed in version 0.0.9. =item Support different types of .env files Unix Shell I command compatible dotenv files use double or single quotation marks (B<"> or B<'>) to define a variable which has spaces. But, for instance, Docker compatible F<.env> files do not use quotation marks. The variable's value begins with B<=> sign and ends with linefeed. You can specify in the dotenv file itself - by using meta commands - which type of file it is. =item Use executable B to bring the variables into your shell The executable is distributed together with Env::Dot package. It is in the directory I