line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## no critic (ValuesAndExpressions::ProhibitConstantPragma) |
2
|
|
|
|
|
|
|
package Env::Dot; |
3
|
1
|
|
|
1
|
|
6625
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# We define our own import routine because |
7
|
|
|
|
|
|
|
# this is the point (when `use Env::Dot` is called) |
8
|
|
|
|
|
|
|
# when we do our magic. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
{ |
11
|
1
|
|
|
1
|
|
7
|
no warnings 'redefine'; ## no critic [TestingAndDebugging::ProhibitNoWarnings] |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2664
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub import { |
14
|
1
|
|
|
1
|
|
10
|
load_vars(); |
15
|
1
|
|
|
|
|
15
|
return; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
584
|
use English qw( -no_match_vars ); # Avoids regex performance penalty in perl 5.18 and earlier |
|
1
|
|
|
|
|
1667
|
|
|
1
|
|
|
|
|
7
|
|
20
|
1
|
|
|
1
|
|
354
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
73
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# ABSTRACT: Read environment variables from .env file |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = '0.007'; # VERSION: generated by DZP::OurPkgVersion |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
361
|
use Env::Dot::Functions qw( get_dotenv_vars interpret_dotenv_filepath_var ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
113
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use constant { |
29
|
1
|
|
|
|
|
314
|
OPTION_FILE_TYPE => q{file:type}, |
30
|
|
|
|
|
|
|
OPTION_FILE_TYPE_PLAIN => q{plain}, |
31
|
|
|
|
|
|
|
OPTION_FILE_TYPE_SHELL => q{shell}, |
32
|
|
|
|
|
|
|
DEFAULT_OPTION_FILE_TYPE => q{shell}, |
33
|
|
|
|
|
|
|
DEFAULT_DOTENV_FILEPATH => q{.env}, |
34
|
|
|
|
|
|
|
INDENT => q{ }, |
35
|
1
|
|
|
1
|
|
10
|
}; |
|
1
|
|
|
|
|
6
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub load_vars { |
38
|
1
|
|
|
1
|
1
|
5
|
my $dotenv_filepath_var = q{ENVDOT_FILEPATHS}; |
39
|
1
|
|
|
|
|
2
|
my @dotenv_filepaths; |
40
|
1
|
50
|
|
|
|
5
|
if ( exists $ENV{$dotenv_filepath_var} ) { |
41
|
1
|
|
|
|
|
5
|
@dotenv_filepaths = interpret_dotenv_filepath_var( $ENV{$dotenv_filepath_var} ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
0
|
0
|
|
|
|
0
|
if ( -f DEFAULT_DOTENV_FILEPATH ) { |
45
|
0
|
|
|
|
|
0
|
@dotenv_filepaths = (DEFAULT_DOTENV_FILEPATH); # The CLI parameter |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
7
|
my @vars = get_dotenv_vars(@dotenv_filepaths); |
50
|
1
|
|
|
|
|
2
|
my %new_env; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Populate new env with the dotenv variables. |
53
|
1
|
|
|
|
|
2
|
foreach my $var (@vars) { |
54
|
|
|
|
|
|
|
### no critic [Variables::RequireLocalizedPunctuationVars] |
55
|
4
|
|
|
|
|
15
|
$new_env{ $var->{'name'} } = $var->{'value'}; |
56
|
|
|
|
|
|
|
} |
57
|
1
|
|
|
|
|
5
|
foreach my $var_name ( sort keys %ENV ) { |
58
|
2
|
|
|
|
|
4
|
$new_env{$var_name} = $ENV{$var_name}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# We need to replace the current %ENV, not change individual values. |
62
|
|
|
|
|
|
|
## no critic [Variables::RequireLocalizedPunctuationVars] |
63
|
1
|
|
|
|
|
12
|
%ENV = %new_env; |
64
|
1
|
|
|
|
|
6
|
return \%ENV; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |