blib/lib/Web/Detect.pm

filter: Statementstmt 73.4% 47 / 64 Branchbran 53.5% 30 / 56 Conditioncond 61.9% 13 / 21 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 62.8% 100 / 159 CC 37 SCAR 47.2
CC
37
Cov
64%
detect_web
137.5
import
4.0
BEGIN
1.0
CRAP 111.8
↑ Summary
1 package Web::Detect;
2  
3 2 our $DATE = '2015-01-03'; # DATE
4 2 our $VERSION = '0.05'; # VERSION
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶sub import {
Subroutine import: called CC=4 SCAR=13.9
10 3 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 2 1 3
11 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶ if ( grep /^detect_web$/, @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^detect_web$/, @_) 1 1 2
13 1 *{ caller() . '::detect_web' } = \&detect_web;
14 }
15  
16 2 ▶ if ( grep /^detect_web_fast$/, @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^detect_web_fast$/, @_) 1 1 2
17 1 *{ caller() . '::detect_web_fast' } = \&detect_web_fast;
18 }
19 }
20 }
21  
22 13 ▶sub detect_web {
Subroutine detect_web: called CC=34 SCAR=49.2
Pod documented
23 13 my ($first) = @_;
24 13 my %res;
25  
26 13 ▶ if ( $ENV{MOD_PERL} ) { # verified on mod_perl 1.3 and mod_perl 2.0
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"MOD_PERL"}) 0 13 13
27 0 $res{mod_perl} = 1;
28 0 ▶ return \%res if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 0 0
29 }
30  
31 13 ▶ if ( $ENV{PLACK_ENV} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PLACK_ENV"}) 0 13 13
32 0 $res{plack} = 1;
33 0 $res{psgi} = 1;
34 0 ▶ return \%res if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 0 0
35 }
36  
37 13 ▶ if ( $ENV{'PANGEA'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PANGEA"}) 7 6 13
38 7 $res{'pangea'} = 1;
39 7 $res{'psgi'} = 1;
40 7 ▶ return \%res if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 2 5 7
41 }
42  
43 11 ▶ if ( $ENV{'CPANEL'} || $ENV{'WHM50'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"CPANEL"} or $ENV{"WHM50"}) 0 11 11
Condition33%1/3
$ENV{"CPANEL"} or $ENV{"WHM50"}
l!l&&r!l&&!r
0011
MC/DC0%0/2
$ENV{"CPANEL"} or $ENV{"WHM50"}
$ENV{"CPANEL"} $ENV{"WHM50"}
Truth table33%1/3
A or B
A= $ENV{"CPANEL"}B= $ENV{"WHM50"}
ABresult
1X1
011
000
44 0 $res{'cpanel'} = 1;
45 0 ▶ return \%res if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 0 0
46 }
47  
48 11 ▶ if ( $ENV{'CATALYST_SCRIPT_GEN'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"CATALYST_SCRIPT_GEN"}) 0 11 11
49 0 $res{'catalyst'} = 1;
50 0 ▶ return \%res if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 0 0
51 }
52  
53 11 ▶ if ( $ENV{'DANCER_APPDIR'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DANCER_APPDIR"}) 0 11 11
54 0 $res{'dancer'} = 1;
55 0 ▶ return \%res if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 0 0
56 }
57  
58 11 ▶ if ( $ENV{'MOJO_EXE'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"MOJO_EXE"}) 0 11 11
59 0 $res{'mojo'} = 1;
60 0 ▶ return \%res if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 0 0
61 }
62  
63 11 ▶ if ( $ENV{'FCGI_ROLE'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"FCGI_ROLE"}) 0 11 11
64 0 $res{'FCGI.pm'} = 1;
65 0 ▶ return \%res if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 0 0
66 }
67  
68 11 ▶ if ( $ENV{'INSTANCE_ID'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"INSTANCE_ID"}) 0 11 11
69 0 $res{'IIS'} = 1;
70 0 ▶ return \%res if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 0 0
71 }
72  
73 # now, do more generic checks after specific server checks:
74 11 ▶ if ( defined $ENV{GATEWAY_INTERFACE} && $ENV{GATEWAY_INTERFACE} =~ m/^CGI/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"GATEWAY_INTERFACE"} and $ENV{"GATEWAY_INTERFACE"} =~ /^CGI/) 9 2 11
Condition66%2/3
defined $ENV{"GATEWAY_INTERFACE"} and $ENV{"GATEWAY_INTERFACE"} =~ /^CGI/
!ll&&!rl&&r
209
MC/DC50%1/2
defined $ENV{"GATEWAY_INTERFACE"} and $ENV{"GATEWAY_INTERFACE"} =~ /^CGI/
defined $ENV{"GATEWAY_INTERFACE"} $ENV{"GATEWAY_INTERFACE"} =~ /^CGI/
Truth table66%2/3
A and B
A= defined $ENV{"GATEWAY_INTERFACE"}B= $ENV{"GATEWAY_INTERFACE"} =~ /^CGI/
ABresult
0X0
100
111
75 9 $res{cgi} = 1;
76 9 ▶ return \%res if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 2 7 9
77 }
78  
79 # General server vars:
80 9 ▶ if ( $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || $ENV{'REMOTE_ADDR'} || $ENV{'HTTPS'} || $ENV{'QUERY_STRING'} || $ENV{'DOCUMENT_ROOT'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"SCRIPT_NAME"} or $ENV{"SCRIPT_FILENAME"} or $ENV{"REMOTE_ADDR"} or $ENV{"HTTPS"} or $ENV{"QUERY_STRING"} or $ENV{"DOCUMENT_ROOT"}) 2 7 9
Condition66%10/15
$ENV{"SCRIPT_NAME"} or $ENV{"SCRIPT_FILENAME"} or $ENV{"REMOTE_ADDR"} or $ENV{"HTTPS"} or $ENV{"QUERY_STRING"} or $ENV{"DOCUMENT_ROOT"}
l!l&&r!l&&!r
207
$ENV{"SCRIPT_NAME"} or $ENV{"SCRIPT_FILENAME"} or $ENV{"REMOTE_ADDR"} or $ENV{"HTTPS"} or $ENV{"QUERY_STRING"}
l!l&&r!l&&!r
207
$ENV{"SCRIPT_NAME"} or $ENV{"SCRIPT_FILENAME"} or $ENV{"REMOTE_ADDR"} or $ENV{"HTTPS"}
l!l&&r!l&&!r
207
$ENV{"SCRIPT_NAME"} or $ENV{"SCRIPT_FILENAME"} or $ENV{"REMOTE_ADDR"}
l!l&&r!l&&!r
207
$ENV{"SCRIPT_NAME"} or $ENV{"SCRIPT_FILENAME"}
l!l&&r!l&&!r
207
MC/DC16%1/6
$ENV{"SCRIPT_NAME"} or $ENV{"SCRIPT_FILENAME"} or $ENV{"REMOTE_ADDR"} or $ENV{"HTTPS"} or $ENV{"QUERY_STRING"} or $ENV{"DOCUMENT_ROOT"}
$ENV{"SCRIPT_NAME"} $ENV{"SCRIPT_FILENAME"} $ENV{"REMOTE_ADDR"} $ENV{"HTTPS"} $ENV{"QUERY_STRING"} $ENV{"DOCUMENT_ROOT"}
Truth table28%2/7
A or B or C or D or E or F
A= $ENV{"SCRIPT_NAME"}B= $ENV{"SCRIPT_FILENAME"}C= $ENV{"REMOTE_ADDR"}D= $ENV{"HTTPS"}E= $ENV{"QUERY_STRING"}F= $ENV{"DOCUMENT_ROOT"}
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
81 2 $res{'general'} = 1;
82 2 ▶ return \%res if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 2 2
83 }
84  
85 # still nothing? yikes ...
86 9 for my $k ( keys %ENV ) {
87 16 ▶ if ( $k =~ m/^(?:HTTP|SERVER|REQUEST)_/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^(?:HTTP|SERVER|REQUEST)_/) 2 14 16
88 2 $res{'general'} += 2;
89 2 ▶ return \%res if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 2 2
90 }
91 }
92  
93 # the way scripts are run in some web servers they are still technically
94 # "interactive", so interactivity is only reliable for this if it is false
95 # (IO::Interactive::Tiny)
96 #
97 # ditto +/- for term detection (Term::Detect)
98  
99 9 ▶ return unless %res;
Branch: 1 branch
BranchTrueFalseTotal
unless %res 2 7 9
100 7 return \%res;
101 }
102  
103 5 ▶sub detect_web_fast {
Subroutine detect_web_fast: called CC=1 SCAR=0.0
Pod documented
104 5 @_ = (1);
105 5 goto &detect_web;
106 }
107  
108 2 1;
109  
110 # ABSTRACT: Detect if program is running under some web environment
111  
112 __END__
↑ Summary