# 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; use 5.010; 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.020'; # 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 { my ($class, $cmd, $args) = @_; # We also allow only: 'use Env::Dot;' croak "Unknown argument '$cmd'" if( $cmd && $cmd ne 'read' ); if( ! load_vars( %{ $args // {} } ) ) { croak 'Errors in environment detected.'; } return; } } 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 =head1 STATUS This module is currently being developed so changes in the API are possible, though not likely. =head1 SYNOPSIS =for test_synopsis BEGIN { die 'SKIP: no .env file here' } # If your dotenv file is `.env`: use Env::Dot; # or use Env::Dot 'read'; print $ENV{'VAR_DEFINED_IN_DOTENV_FILE'}; # If you have a dotenv file in a different filepath: use Env::Dot read => { dotenv_file => '/other/path/my_environment.env', }; =head1 DESCRIPTION More flexibility in how you manage and use your F<.env> file. =for stopwords dotenv 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 =for stopwords dotenv 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. =for stopwords dotenv You can specify in the dotenv file itself - by using meta commands - which type of file it is. =for stopwords envdot =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