line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::EnvironmentDetector; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23691
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
894
|
use Sys::Hostname; |
|
1
|
|
|
|
|
1791
|
|
|
1
|
|
|
|
|
278
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub is_environment { |
9
|
0
|
|
|
0
|
1
|
|
my ($c, $env_str) = @_; |
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
|
|
|
my $config = $c->config->{environmentdetector}; |
12
|
|
|
|
|
|
|
|
13
|
0
|
0
|
|
|
|
|
if( exists $config->{$env_str} ) { |
14
|
0
|
|
|
|
|
|
foreach my $match_type ( keys %{ $config->{$env_str} } ) { |
|
0
|
|
|
|
|
|
|
15
|
0
|
0
|
|
|
|
|
if( $match_type eq "env" ) { |
|
|
0
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $env_key = $config->{$env_str}->{$match_type}[0]; |
17
|
0
|
|
|
|
|
|
my $env_pattern = $config->{$env_str}->{$match_type}[1]; |
18
|
0
|
|
|
|
|
|
return ($ENV{$env_key} =~ /$env_pattern/); |
19
|
|
|
|
|
|
|
} elsif( $match_type eq "hostname" ) { |
20
|
0
|
|
|
|
|
|
return (hostname =~ /$config->{$env_str}{hostname}/); |
21
|
|
|
|
|
|
|
} else { |
22
|
|
|
|
|
|
|
# unsupported matching criteria |
23
|
0
|
|
|
|
|
|
return undef; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# in the event you have not configured the pattern |
29
|
|
|
|
|
|
|
# match for this environment then always return |
30
|
|
|
|
|
|
|
# undef so you will never detect this environment |
31
|
|
|
|
|
|
|
# as true. |
32
|
0
|
|
|
|
|
|
return undef; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
__END__ |