line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::ENV; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
173993
|
use strict; |
|
7
|
|
|
|
|
41
|
|
|
7
|
|
|
|
|
155
|
|
4
|
7
|
|
|
7
|
|
25
|
use warnings; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
126
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
23
|
use Carp; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
381
|
|
7
|
7
|
|
|
7
|
|
29
|
use File::Spec; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
364
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.17'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub import { |
12
|
14
|
|
|
14
|
|
64168
|
my $class = shift; |
13
|
14
|
|
|
|
|
27
|
my $package = caller(0); |
14
|
|
|
|
|
|
|
|
15
|
7
|
|
|
7
|
|
34
|
no strict 'refs'; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
724
|
|
16
|
14
|
100
|
|
|
|
37
|
if (__PACKAGE__ eq $class) { |
17
|
9
|
|
|
|
|
13
|
my $name = shift; |
18
|
9
|
|
|
|
|
18
|
my %opts = @_; |
19
|
|
|
|
|
|
|
|
20
|
9
|
|
|
|
|
11
|
push @{"$package\::ISA"}, __PACKAGE__; |
|
9
|
|
|
|
|
79
|
|
21
|
|
|
|
|
|
|
|
22
|
9
|
|
|
|
|
21
|
for my $method (qw/common config parent load/) { |
23
|
36
|
|
|
|
|
40
|
*{"$package\::$method"} = \&{__PACKAGE__ . "::" . $method} |
|
36
|
|
|
|
|
105
|
|
|
36
|
|
|
|
|
62
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
7
|
|
|
7
|
|
37
|
no warnings 'once'; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
1216
|
|
27
|
9
|
|
|
|
|
68528
|
${"$package\::data"} = +{ |
28
|
|
|
|
|
|
|
common => {}, |
29
|
|
|
|
|
|
|
envs => {}, |
30
|
|
|
|
|
|
|
name => $name, |
31
|
|
|
|
|
|
|
default => $opts{default} || 'default', |
32
|
|
|
|
|
|
|
export => $opts{export}, |
33
|
9
|
|
100
|
|
|
67
|
_local => [], |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
} else { |
36
|
5
|
|
|
|
|
65
|
my %opts = @_; |
37
|
5
|
|
|
|
|
14
|
my $data = _data($class); |
38
|
5
|
100
|
100
|
|
|
129
|
if (my $export = $opts{export} || $data->{export}) { |
39
|
2
|
|
|
4
|
|
15
|
*{"$package\::$export"} = sub { $class }; |
|
2
|
|
|
|
|
1167
|
|
|
4
|
|
|
|
|
26
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _data { |
45
|
148
|
|
66
|
148
|
|
320
|
my $package = shift || caller(1); |
46
|
7
|
|
|
7
|
|
43
|
no strict 'refs'; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
233
|
|
47
|
7
|
|
|
7
|
|
35
|
no warnings 'once'; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
3798
|
|
48
|
148
|
|
|
|
|
160
|
${"$package\::data"}; |
|
148
|
|
|
|
|
356
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub common ($) { ## no critic |
52
|
8
|
|
|
8
|
1
|
3543
|
my ($hash) = @_; |
53
|
8
|
|
|
|
|
21
|
_data->{common} = $hash; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub config ($$) { ## no critic |
57
|
13
|
|
|
13
|
1
|
37
|
my ($name, $hash) = @_; |
58
|
13
|
|
|
|
|
18
|
_data->{envs}->{$name} = $hash; |
59
|
13
|
|
|
|
|
22
|
undef _data->{_merged}->{$name}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub load ($) { ## no critic |
63
|
10
|
|
|
10
|
1
|
2878
|
my $filename = shift; |
64
|
10
|
100
|
|
|
|
101
|
$filename = File::Spec->catfile('.', $filename) unless File::Spec->file_name_is_absolute($filename); |
65
|
10
|
|
|
|
|
1258
|
my $hash = do "$filename"; |
66
|
|
|
|
|
|
|
|
67
|
10
|
100
|
|
|
|
175
|
croak $@ if $@; |
68
|
9
|
100
|
|
|
|
231
|
croak $^E unless defined $hash; |
69
|
8
|
100
|
|
|
|
15
|
unless (ref($hash) eq 'HASH') { |
70
|
1
|
|
|
|
|
74
|
croak "$filename does not return HashRef."; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
7
|
100
|
|
|
|
28
|
wantarray ? %$hash : $hash; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub parent ($) { ## no critic |
77
|
2
|
|
|
2
|
1
|
7
|
my ($name) = @_; |
78
|
2
|
50
|
|
|
|
3
|
%{ _data->{envs}->{$name} || {} }; |
|
2
|
|
|
|
|
3
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub current { |
82
|
36
|
|
|
36
|
1
|
57
|
my ($package) = @_; |
83
|
36
|
|
|
|
|
72
|
my $data = _data($package); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $vals = $data->{_merged}->{$package->env} ||= +{ |
86
|
25
|
|
|
|
|
56
|
%{ $data->{common} }, |
87
|
25
|
100
|
|
|
|
48
|
%{ $data->{envs}->{$package->env} || {} }, |
88
|
36
|
|
100
|
|
|
93
|
(map { %$_ } @{ $data->{_local} }), |
|
17
|
|
|
|
|
83
|
|
|
25
|
|
|
|
|
121
|
|
89
|
|
|
|
|
|
|
}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub param { |
93
|
32
|
|
|
32
|
1
|
109
|
my ($package, $name) = @_; |
94
|
32
|
|
|
|
|
77
|
$package->current->{$name}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub local { |
98
|
8
|
|
|
8
|
1
|
105
|
my ($package, %hash) = @_; |
99
|
8
|
100
|
|
|
|
158
|
not defined wantarray and croak "local returns guard object; Can't use in void context."; |
100
|
|
|
|
|
|
|
|
101
|
7
|
|
|
|
|
10
|
my $data = _data($package); |
102
|
7
|
|
|
|
|
10
|
push @{ $data->{_local} }, \%hash; |
|
7
|
|
|
|
|
15
|
|
103
|
7
|
|
|
|
|
14
|
undef $data->{_merged}; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
bless sub { |
106
|
7
|
|
|
7
|
|
10
|
@{ $data->{_local} } = grep { $_ != \%hash } @{ $data->{_local} }; |
|
7
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
27
|
|
|
7
|
|
|
|
|
13
|
|
107
|
7
|
|
|
|
|
36
|
undef $data->{_merged}; |
108
|
7
|
|
|
|
|
32
|
}, 'Config::ENV::Local'; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub env { |
112
|
64
|
|
|
64
|
1
|
182
|
my ($package) = @_; |
113
|
64
|
|
|
|
|
89
|
my $data = _data($package); |
114
|
64
|
100
|
|
|
|
361
|
$ENV{$data->{name}} || $data->{default}; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
{ |
118
|
|
|
|
|
|
|
package |
119
|
|
|
|
|
|
|
Config::ENV::Local; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub DESTROY { |
122
|
7
|
|
|
7
|
|
1768
|
my $self = shift; |
123
|
7
|
|
|
|
|
15
|
$self->(); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
}; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
__END__ |