line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## no critic (ValuesAndExpressions::ProhibitConstantPragma) |
2
|
|
|
|
|
|
|
package Env::Dot::ScriptFunctions; |
3
|
1
|
|
|
1
|
|
227919
|
use strict; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
5
|
1
|
|
|
1
|
|
645
|
use Data::Dumper; |
|
1
|
|
|
|
|
6467
|
|
|
1
|
|
|
|
|
71
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Exporter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
9
|
|
|
|
|
|
|
convert_variables_into_commands |
10
|
|
|
|
|
|
|
); |
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [qw( convert_variables_into_commands )], ); |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
490
|
use English qw( -no_match_vars ); # Avoids regex performance penalty in perl 5.18 and earlier |
|
1
|
|
|
|
|
3685
|
|
|
1
|
|
|
|
|
6
|
|
14
|
1
|
|
|
1
|
|
367
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
74
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# ABSTRACT: Read environment variables from .env file |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.007'; # VERSION: generated by DZP::OurPkgVersion |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use constant { |
21
|
1
|
|
|
|
|
613
|
OPTION_FILE_TYPE => q{file:type}, |
22
|
|
|
|
|
|
|
OPTION_FILE_TYPE_PLAIN => q{plain}, |
23
|
|
|
|
|
|
|
OPTION_FILE_TYPE_SHELL => q{shell}, |
24
|
|
|
|
|
|
|
DEFAULT_OPTION_FILE_TYPE => q{shell}, |
25
|
1
|
|
|
1
|
|
7
|
}; |
|
1
|
|
|
|
|
2
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my %DOTENV_OPTIONS = ( |
28
|
|
|
|
|
|
|
'file:type' => 1, |
29
|
|
|
|
|
|
|
'var:allow_interpolate' => 1, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my %VAR_OUTPUT = ( |
33
|
|
|
|
|
|
|
q{sh} => \&_convert_var_to_sh, |
34
|
|
|
|
|
|
|
q{csh} => \&_convert_var_to_csh, |
35
|
|
|
|
|
|
|
q{fish} => \&_convert_var_to_fish, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub convert_variables_into_commands { |
39
|
2
|
|
|
2
|
1
|
2463
|
my ( $shell, @vars ) = @_; |
40
|
2
|
|
|
|
|
5
|
my $out = q{}; |
41
|
2
|
|
|
|
|
5
|
foreach my $var (@vars) { |
42
|
4
|
|
|
|
|
13
|
$out .= _convert_variable( $shell, $var ); |
43
|
4
|
|
|
|
|
15
|
$out .= "\n"; |
44
|
|
|
|
|
|
|
} |
45
|
2
|
|
|
|
|
7
|
return $out; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Private subroutines |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _convert_variable { |
51
|
4
|
|
|
4
|
|
7
|
my ( $shell, $var ) = @_; |
52
|
4
|
50
|
|
|
|
9
|
if ( exists $VAR_OUTPUT{$shell} ) { |
53
|
4
|
|
|
|
|
7
|
return &{ $VAR_OUTPUT{$shell} }($var); |
|
4
|
|
|
|
|
7
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
0
|
|
|
|
|
0
|
croak "Unknown shell: $shell"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _convert_var_to_sh { |
61
|
7
|
|
|
7
|
|
7256
|
my ($var) = @_; |
62
|
|
|
|
|
|
|
my ( $name, $value, $want_export, $allow_interpolate ) = |
63
|
7
|
|
|
|
|
22
|
( $var->{'name'}, $var->{'value'}, $var->{'opts'}->{'export'}, $var->{'opts'}->{'allow_interpolate'}, ); |
64
|
7
|
100
|
|
|
|
14
|
my $quote = $allow_interpolate ? q{"} : q{'}; |
65
|
7
|
100
|
|
|
|
15
|
if ($want_export) { |
66
|
4
|
|
|
|
|
23
|
return sprintf "%s=$quote%s$quote; export %s", $name, $value, $name; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
3
|
|
|
|
|
18
|
return sprintf "%s=$quote%s$quote", $name, $value; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _convert_var_to_csh { |
74
|
3
|
|
|
3
|
|
3273
|
my ($var) = @_; |
75
|
|
|
|
|
|
|
my ( $name, $value, $want_export, $allow_interpolate ) = |
76
|
3
|
|
|
|
|
9
|
( $var->{'name'}, $var->{'value'}, $var->{'opts'}->{'export'}, $var->{'opts'}->{'allow_interpolate'}, ); |
77
|
3
|
100
|
|
|
|
19
|
my $quote = $allow_interpolate ? q{"} : q{'}; |
78
|
3
|
100
|
|
|
|
8
|
if ($want_export) { |
79
|
2
|
|
|
|
|
31
|
return sprintf "setenv %s $quote%s$quote", $name, $value; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { |
82
|
1
|
|
|
|
|
6
|
return sprintf "set %s $quote%s$quote", $name, $value; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _convert_var_to_fish { |
87
|
0
|
|
|
0
|
|
|
my ($var) = @_; |
88
|
|
|
|
|
|
|
my ( $name, $value, $want_export, $allow_interpolate ) = |
89
|
0
|
|
|
|
|
|
( $var->{'name'}, $var->{'value'}, $var->{'opts'}->{'export'}, $var->{'opts'}->{'allow_interpolate'}, ); |
90
|
0
|
0
|
|
|
|
|
my $quote = $allow_interpolate ? q{"} : q{'}; |
91
|
0
|
|
|
|
|
|
return sprintf "set -e %s; set -x -U %s $quote%s$quote", $name, $name, $value; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |