line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Run::Env; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
78407
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
199
|
|
4
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
73
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
4002
|
use Carp::Clan (); |
|
2
|
|
|
|
|
17717
|
|
|
2
|
|
|
|
|
51
|
|
7
|
2
|
|
|
2
|
|
2301
|
use File::Spec (); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
52
|
|
8
|
2
|
|
|
2
|
|
2675
|
use FindBin::Real (); |
|
2
|
|
|
|
|
3654
|
|
|
2
|
|
|
|
|
57
|
|
9
|
2
|
|
|
2
|
|
2510
|
use List::MoreUtils 'any'; |
|
2
|
|
|
|
|
4609
|
|
|
2
|
|
|
|
|
13968
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @running_envs = qw{ |
15
|
|
|
|
|
|
|
development |
16
|
|
|
|
|
|
|
uat |
17
|
|
|
|
|
|
|
staging |
18
|
|
|
|
|
|
|
production |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @execution_modes = qw{ |
22
|
|
|
|
|
|
|
cgi |
23
|
|
|
|
|
|
|
mod_perl |
24
|
|
|
|
|
|
|
shell |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $os_root_dir = File::Spec->rootdir(); |
29
|
|
|
|
|
|
|
our @os_conf_location = ($os_root_dir, 'etc'); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub import { |
32
|
6
|
|
|
6
|
|
587
|
my $class = shift; |
33
|
|
|
|
|
|
|
|
34
|
6
|
|
|
|
|
186
|
foreach my $env (@_) { |
35
|
6
|
50
|
|
|
|
18
|
next if not $env; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$env eq 'testing' ? set_testing() |
38
|
|
|
|
|
|
|
: $env eq '-testing' ? clear_testing() |
39
|
|
|
|
|
|
|
: $env eq 'debug' ? set_debug() |
40
|
|
|
|
|
|
|
: $env eq '-debug' ? clear_debug() |
41
|
4
|
|
|
4
|
|
56
|
: any { $env eq $_ } @running_envs |
42
|
|
|
|
|
|
|
? set($env) |
43
|
0
|
|
|
0
|
|
0
|
: any { $env eq $_ } @execution_modes |
44
|
6
|
0
|
|
|
|
58
|
? set_execution($env) |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
45
|
|
|
|
|
|
|
: Carp::Clan::croak 'no such env/mode: '.$env |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
do { |
50
|
|
|
|
|
|
|
our $running_env = set(detect_running_env()); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub detect_running_env { |
53
|
2
|
50
|
|
2
|
1
|
19
|
return $ENV{'RUN_ENV_current'} |
54
|
|
|
|
|
|
|
if $ENV{'RUN_ENV_current'}; |
55
|
|
|
|
|
|
|
|
56
|
2
|
50
|
|
|
|
472
|
return 'development' |
57
|
|
|
|
|
|
|
if (-e File::Spec->catfile(@os_conf_location, 'development-machine')); |
58
|
2
|
50
|
|
|
|
63
|
return 'uat' |
59
|
|
|
|
|
|
|
if (-e File::Spec->catfile(@os_conf_location, 'uat-machine')); |
60
|
2
|
50
|
|
|
|
51
|
return 'staging' |
61
|
|
|
|
|
|
|
if (-e File::Spec->catfile(@os_conf_location, 'staging-machine')); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# default is production |
64
|
2
|
|
|
|
|
12
|
return 'production'; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _decide { |
68
|
14
|
100
|
|
14
|
|
67
|
return 1 if $running_env eq shift; |
69
|
7
|
|
|
|
|
25
|
return 0; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _set { |
73
|
8
|
|
|
8
|
|
26
|
my $set_running_env = shift; |
74
|
8
|
|
|
|
|
16
|
$running_env = $set_running_env; |
75
|
8
|
|
|
|
|
87
|
$ENV{'RUN_ENV_current'} = $set_running_env; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub current { |
79
|
0
|
|
|
0
|
1
|
0
|
return $running_env; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
*dev = *development; |
83
|
|
|
|
|
|
|
sub development { |
84
|
4
|
|
|
4
|
1
|
17
|
return _decide('development'); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub uat { |
88
|
2
|
|
|
2
|
1
|
6
|
return _decide('uat'); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
*stg = *staging; |
92
|
|
|
|
|
|
|
sub staging { |
93
|
4
|
|
|
4
|
1
|
13
|
return _decide('staging'); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
*prod = *production; |
97
|
|
|
|
|
|
|
sub production { |
98
|
4
|
|
|
4
|
1
|
12
|
return _decide('production'); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub set { |
102
|
6
|
|
|
6
|
1
|
13
|
my $set_running_env = shift; |
103
|
|
|
|
|
|
|
|
104
|
6
|
100
|
|
|
|
55
|
if ($set_running_env eq 'development') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
105
|
1
|
|
|
|
|
10
|
set_development(); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
elsif ($set_running_env eq 'uat') { |
108
|
1
|
|
|
|
|
4
|
set_uat(); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
elsif ($set_running_env eq 'staging') { |
111
|
1
|
|
|
|
|
3
|
set_staging(); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
elsif ($set_running_env eq 'production') { |
114
|
3
|
|
|
|
|
12
|
set_production(); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else { |
117
|
0
|
|
|
|
|
0
|
Carp::Clan::croak 'no such running environment: '.$set_running_env; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub set_development { |
122
|
1
|
|
|
1
|
1
|
3
|
_set('development'); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub set_uat { |
126
|
2
|
|
|
2
|
1
|
77280
|
_set('uat'); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub set_staging { |
130
|
2
|
|
|
2
|
1
|
8
|
_set('staging'); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub set_production { |
134
|
3
|
|
|
3
|
1
|
12
|
_set('production'); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
}; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
do { |
140
|
|
|
|
|
|
|
our $debug_mode = set_debug(detect_debug()); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub detect_debug { |
143
|
2
|
50
|
|
2
|
1
|
8
|
return 1 if $ENV{'RUN_ENV_debug'}; |
144
|
2
|
50
|
|
0
|
|
203
|
return 1 if any { $_ eq '--debug' } @ARGV; |
|
0
|
|
|
|
|
0
|
|
145
|
2
|
|
|
|
|
13
|
return 0; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub debug { |
149
|
3
|
|
|
3
|
1
|
22
|
return $debug_mode; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub set_debug { |
153
|
|
|
|
|
|
|
# turn on debugging when called whitout argument |
154
|
6
|
100
|
|
6
|
1
|
28
|
return set_debug(1) if (@_ == 0); |
155
|
|
|
|
|
|
|
|
156
|
4
|
|
|
|
|
17
|
$debug_mode = shift; |
157
|
4
|
100
|
|
|
|
13
|
if ($debug_mode) { |
158
|
2
|
|
|
|
|
12
|
$ENV{'RUN_ENV_debug'} = $debug_mode; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
else { |
161
|
2
|
|
|
|
|
6
|
clear_debug(); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub clear_debug { |
166
|
2
|
|
|
2
|
1
|
3
|
$debug_mode = 0; |
167
|
2
|
|
|
|
|
13
|
delete $ENV{'RUN_ENV_debug'}; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
}; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
do { |
173
|
|
|
|
|
|
|
our $execution_mode = set_execution(detect_execution()); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub detect_execution { |
176
|
4
|
100
|
|
4
|
1
|
22
|
return 'mod_perl' |
177
|
|
|
|
|
|
|
if exists $ENV{'MOD_PERL'}; |
178
|
3
|
100
|
|
|
|
14
|
return 'cgi' |
179
|
|
|
|
|
|
|
if exists $ENV{'REQUEST_METHOD'}; |
180
|
2
|
|
|
|
|
9
|
return 'shell'; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub _decide_execution { |
184
|
1
|
50
|
|
1
|
|
7
|
return 1 if $execution_mode eq shift; |
185
|
0
|
|
|
|
|
0
|
return 0; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub execution { |
189
|
0
|
|
|
0
|
1
|
0
|
return $execution_mode; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub cgi { |
193
|
0
|
|
|
0
|
1
|
0
|
return _decide_execution('cgi'); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub mod_perl { |
197
|
0
|
|
|
0
|
1
|
0
|
return _decide_execution('mod_perl'); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub shell { |
201
|
1
|
|
|
1
|
1
|
4
|
return _decide_execution('shell'); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub set_execution { |
205
|
2
|
|
|
2
|
1
|
5
|
my $set_execution = shift; |
206
|
|
|
|
|
|
|
|
207
|
2
|
50
|
|
|
|
24
|
if ($set_execution eq 'cgi') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
208
|
0
|
|
|
|
|
0
|
set_cgi(); |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
elsif ($set_execution eq 'mod_perl') { |
211
|
0
|
|
|
|
|
0
|
set_mod_perl(); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
elsif ($set_execution eq 'shell') { |
214
|
2
|
|
|
|
|
7
|
set_shell(); |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
else { |
217
|
0
|
|
|
|
|
0
|
Carp::Clan::croak 'no such execution mode: '.$set_execution; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub set_cgi { |
222
|
0
|
|
|
0
|
1
|
0
|
_set_execution('cgi'); |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub set_mod_perl { |
226
|
0
|
|
|
0
|
1
|
0
|
_set_execution('mod_perl'); |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub set_shell { |
230
|
2
|
|
|
2
|
1
|
15
|
_set_execution('shell'); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub _set_execution { |
234
|
2
|
|
|
2
|
|
5
|
my $set_execution = shift; |
235
|
2
|
|
|
|
|
7
|
$execution_mode = $set_execution; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
}; |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
do { |
241
|
|
|
|
|
|
|
our $testing = set_testing(detect_testing()); |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub detect_testing { |
244
|
4
|
50
|
|
4
|
1
|
248621
|
return 1 |
245
|
|
|
|
|
|
|
if $ENV{'RUN_ENV_testing'}; |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
# testing if current folder is 't' |
248
|
4
|
|
66
|
|
|
14
|
my @bin = eval { FindBin::Real::Bin() } || File::Spec->rootdir(); |
249
|
4
|
|
|
|
|
1919
|
my @current_path = File::Spec->splitdir(@bin); |
250
|
4
|
100
|
|
|
|
38
|
return 1 |
251
|
|
|
|
|
|
|
if (pop @current_path eq 't'); |
252
|
|
|
|
|
|
|
|
253
|
1
|
|
|
|
|
8
|
return 0; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub testing { |
257
|
3
|
|
|
3
|
1
|
16
|
return $testing; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub set_testing { |
261
|
|
|
|
|
|
|
# turn on testing when called whitout argument |
262
|
2
|
50
|
|
2
|
1
|
8
|
return set_testing(1) if (@_ == 0); |
263
|
|
|
|
|
|
|
|
264
|
2
|
|
|
|
|
4
|
$testing = shift; |
265
|
2
|
50
|
|
|
|
7
|
if ($testing) { |
266
|
2
|
|
|
|
|
16
|
$ENV{'RUN_ENV_testing'} = $testing; |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
else { |
269
|
0
|
|
|
|
|
0
|
clear_testing(); |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
sub clear_testing { |
274
|
1
|
|
|
1
|
1
|
2
|
$testing = 0; |
275
|
1
|
|
|
|
|
9
|
delete $ENV{'RUN_ENV_testing'}; |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
}; |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
qq/ I wonder what is Domm actually listenning to at the moment ;) /; |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
__END__ |