lib/CGI/CurlLog.pm

filter: Statementstmt 57.7% 41 / 71 Branchbran 45.2% 19 / 42 Conditioncond 27.2% 3 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 49.6% 66 / 133 CC 2 SCAR 8.9
CC
2
Cov
51%
END
3.9
BEGIN
1.0
BEGIN
1.0
CRAP 2.4
« blib/lib/CGI/CurlLog.pm ↑ Summary
1 package CGI::CurlLog;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = "0.02";
6  
7 1 ▶if (!$ENV{"GATEWAY_INTERFACE"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"GATEWAY_INTERFACE"}) 0 1 1
8 0 return 1;
9 }
10  
11 1 ▶our $log_file ||= "~/curl.log";
Condition50%1/2
our $log_file ||= "~/curl.log"
l!l
10
MC/DC0%0/1
our $log_file ||= "~/curl.log"
our $log_file
Truth table50%1/2
A
A= our $log_file
Aresult
11
00
12 1 ▶our $log_output = defined $log_output ? $log_output : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $CGI::CurlLog::log_output ? : 1 0 1
13 1 ▶our $curl_options = defined $curl_options ? $curl_options : "-k";
Branch: 1 branch
BranchTrueFalseTotal
defined $CGI::CurlLog::curl_options ? : 0 1 1
14  
15 1 my $cmd = "curl ";
16 1 ▶my $url = $ENV{"HTTPS"} ? "https://" : "http://";
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'HTTPS'} ? : 0 1 1
17 1 ▶$url .= $ENV{"HTTP_HOST"} || $ENV{"SERVER_NAME"} || $ENV{"SERVER_ADDR"};
Condition33%2/6
$ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'} || $ENV{'SERVER_ADDR'}
l!l&&r!l&&!r
100
$ENV{"HTTP_HOST"} or $ENV{"SERVER_NAME"}
l!l&&r!l&&!r
100
MC/DC0%0/3
$ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'} || $ENV{'SERVER_ADDR'}
$ENV{"HTTP_HOST"} $ENV{"SERVER_NAME"} $ENV{'SERVER_ADDR'}
Truth table0%0/4
A or B || C
A= $ENV{"HTTP_HOST"}B= $ENV{"SERVER_NAME"}C= $ENV{'SERVER_ADDR'}
ABCresult
1XX1
01X1
0011
0000
18 1 $url .= $ENV{"REQUEST_URI"};
19 1 ▶if ($url =~ /[=&;?]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /[=&;?]/) { } 1 0 1
20 1 $cmd .= "\"$url\" ";
21 }
22 else {
23 0 $cmd .= "$url ";
24 }
25 1 ▶if ($curl_options) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CGI::CurlLog::curl_options) 1 0 1
26 1 $cmd .= "$curl_options ";
27 }
28 1 ▶if ($ENV{"REQUEST_METHOD"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"REQUEST_METHOD"}) 0 1 1
29 0 ▶ if ($ENV{"REQUEST_METHOD"} ne "GET" || $ENV{"CONTENT_LENGTH"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"REQUEST_METHOD"} ne "GET" or $ENV{"CONTENT_LENGTH"}) 0 0 0
Condition0%0/3
$ENV{"REQUEST_METHOD"} ne "GET" or $ENV{"CONTENT_LENGTH"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"REQUEST_METHOD"} ne "GET" or $ENV{"CONTENT_LENGTH"}
$ENV{"REQUEST_METHOD"} ne "GET" $ENV{"CONTENT_LENGTH"}
Truth table0%0/3
A or B
A= $ENV{"REQUEST_METHOD"} ne "GET"B= $ENV{"CONTENT_LENGTH"}
ABresult
1X1
011
000
30 0 $cmd .= "-X $ENV{REQUEST_METHOD} ";
31 }
32 }
33 1 ▶if ($ENV{"CONTENT_TYPE"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"CONTENT_TYPE"}) 0 1 1
34 0 $cmd .= "-H \"Content-Type: $ENV{CONTENT_TYPE}\" ";
35 }
36 1 ▶if ($ENV{"HTTP_ACCEPT"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_ACCEPT"}) 0 1 1
37 0 $cmd .= "-H \"Accept: $ENV{HTTP_ACCEPT}\" ";
38 }
39 1 ▶if ($ENV{"HTTP_AUTHORIZATION"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_AUTHORIZATION"}) 0 1 1
40 0 $cmd .= "-H \"Authorization: $ENV{HTTP_AUTHORIZATION}\" ";
41 }
42 1 ▶if ($ENV{"HTTP_COOKIE"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_COOKIE"}) 0 1 1
43 0 $cmd .= "-H \"Cookie: $ENV{HTTP_COOKIE}\" ";
44 }
45 # if ($ENV{"HTTP_USER_AGENT"}) {
46 # $cmd .= "-H \"UserAgent: $ENV{HTTP_USER_AGENT}\" ";
47 # }
48  
49 1 ▶if ($ENV{"CONTENT_LENGTH"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"CONTENT_LENGTH"}) 0 1 1
50 0 my $input = do {local $/; <STDIN>};
51 0 close STDIN;
52 0 open STDIN, "<", \$input;
53 0 my $input2 = $input;
54 0 $input2 =~ s{([\\\$"])}{\\$1}g;
55 0 $cmd .= "-d \"$input2\" ";
56 }
57 1 $cmd =~ s/\s*$//;
58  
59 1 my $logfh;
60 1 ▶if ($log_file eq "STDOUT") {
Branch: 3 branches
BranchTrueFalseTotal
if ($CGI::CurlLog::log_file eq 'STDOUT') { } 0 1 1
elsif ($CGI::CurlLog::log_file eq 'STDERR') { } 0 1 1
elsif ($CGI::CurlLog::log_file =~ m[^~/]) { } 0 1 1
61 0 $logfh = \*STDOUT;
62 }
63 elsif ($log_file eq "STDERR") {
64 0 $logfh = \*STDERR;
65 }
66 elsif ($log_file =~ m{^~/}) {
67 0 my $home = (getpwuid($>))[7];
68 0 $log_file =~ s{^~/}{$home/};
69 0 ▶ open $logfh, ">>", $log_file or die "Can't open $log_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $logfh, ">>", $CGI::CurlLog::log_file or die "Can't open $CGI::CurlLog::log_file: $!" 0 0 0
70 }
71 else {
72 1 ▶ open $logfh, ">>", $log_file or die "Can't open $log_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $logfh, ">>", $CGI::CurlLog::log_file or die "Can't open $CGI::CurlLog::log_file: $!" 0 1 1
73 }
74 1 select($logfh);
75 1 $| = 1;
76 1 select(STDOUT);
77  
78 1 print $logfh "# " . localtime() . " request from $ENV{REMOTE_ADDR}\n";
79 1 print $logfh "$cmd\n";
80 1 ▶if (!$log_output) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($CGI::CurlLog::log_output) 1 0 1
81 1 close $logfh;
82 }
83  
84 1 my $stdout;
85 1 my $output = "";
86  
87 1 ▶if ($log_output) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CGI::CurlLog::log_output) 0 1 1
88 0 open $stdout, ">&", STDOUT;
89 0 close STDOUT;
90 0 open STDOUT, ">", \$output;
91 }
92  
93 END {
94 1 ▶ return if !$log_output;
Subroutine END: called CC=2 SCAR=13.6
Branch: 1 branch
BranchTrueFalseTotal
unless $CGI::CurlLog::log_output 1 0 1
95 0 open STDOUT, ">&", $stdout;
96 0 print $output;
97 0 $output =~ s/\r//g;
98 0 print $logfh "# " . localtime() . " response\n";
99 0 print $logfh $output . "\n";
100 0 close $logfh;
101 }
102  
103 1 1;
104  
105 __END__
« blib/lib/CGI/CurlLog.pm ↑ Summary