Engine/MinimalCGI.pm

filter: Statementstmt 89.4% 68 / 76 Branchbran 40.0% 8 / 20 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 88.4% 23 / 26 Podpod 0.0% 0 / 2 totaltotal 71.5% 103 / 144 SCAR 29.4
CC
15
Cov
74%
hostname
6.0
protocol
6.0
upload
6.0
CRAP 18.9
« Engine/Role/RequestBuilder/Standard.pm ↑ Summary Engine/Interface/ModPerl.pm »
1 package HTTP::Engine::MinimalCGI;
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 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use HTTP::Headers::Fast ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use HTTP::Engine::ResponseFinalizer ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use CGI::Simple ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 my $CRLF = "\015\012";
10  
11 sub new {
12 6 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
13 6 bless { @_ }, $class;
14 }
15  
16 sub run {
17 6 ▶ my ($self, ) = @_;
Subroutine run: called CC=3 SCAR=12.0
Pod undocumented
18  
19 ### run handler
20 6 my $req = HTTP::Engine::Request->new();
21 6 my $res = $self->{request_handler}->( $req );
22 6 ▶ unless ( Scalar::Util::blessed($res) && $res->isa('HTTP::Engine::Response') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($res) and $res->isa("HTTP::Engine::Response")) 0 6 6
Condition33%1/3
builtin::blessed($res) and $res->isa("HTTP::Engine::Response")
!ll&&!rl&&r
006
MC/DC0%0/2
builtin::blessed($res) and $res->isa("HTTP::Engine::Response")
builtin::blessed($res) $res->isa("HTTP::Engine::Response")
Truth table33%1/3
A and B
A= builtin::blessed($res)B= $res->isa("HTTP::Engine::Response")
ABresult
0X0
100
111
23 0 die "You should return instance of HTTP::Engine::Response.";
24 }
25 6 HTTP::Engine::ResponseFinalizer->finalize($req => $res);
26 6 print join(
27 '',
28 $res->headers->as_string_without_sort($CRLF),
29 $CRLF,
30 $res->body
31 );
32 }
33  
34 {
35 package # hide from pause
36 HTTP::Engine;
37  
38 sub new {
39 6 ▶ my ($class, %args) = @_;
Subroutine new: called CC=3 SCAR=11.8
40 6 ▶ unless (Scalar::Util::blessed($args{interface})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($args{"interface"})) 6 0 6
41 6 ▶ if ($args{interface}->{module} ne 'MinimalCGI') {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"interface"}{"module"} ne "MinimalCGI") 0 6 6
42 0 die "MinimalCGI is the only interface supported. Use the real HTTP::Engine for others.";
43 }
44 $args{interface} = HTTP::Engine::MinimalCGI->new(
45 request_handler => $args{interface}->{request_handler}
46 6 );
47 }
48 6 bless { interface => $args{interface} }, $class;
49 }
50  
51 6 ▶ sub run { $_[0]->{interface}->run() }
Subroutine run: called CC=1 SCAR=0.0
52 }
53  
54  
55 {
56 1 package # hide from pause
57 HTTP::Engine::Response;
58  
59 sub new {
60 6 ▶ my ($class, %args) = @_;
Subroutine new: called CC=1 SCAR=0.0
61 6 bless {
62 status => 200,
63 body => '',
64 headers => HTTP::Headers::Fast->new(),
65 %args,
66 }, $class;
67 }
68 sub header {
69 14 ▶ my $self = shift;
Subroutine header: called CC=1 SCAR=0.0
70 14 $self->{headers}->header(@_);
71 }
72 sub headers {
73 7 ▶ my $self = shift;
Subroutine headers: called CC=1 SCAR=0.0
74 7 $self->{headers};
75 }
76 sub status {
77 12 ▶ my $self = shift;
Subroutine status: called CC=2 SCAR=7.1
78 12 ▶ $self->{status} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 12 12
79 12 $self->{status};
80 }
81 sub body {
82 30 ▶ my $self = shift;
Subroutine body: called CC=2 SCAR=7.1
83 30 ▶ $self->{body} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 30 30
84 30 $self->{body};
85 }
86 18 ▶ sub protocol { 'HTTP/1.0' };
Subroutine protocol: called CC=1 SCAR=0.0
87 6 ▶ sub content_length { my $self = shift; $self->{headers}->content_length(@_) };
Subroutine content_length: called CC=1 SCAR=0.0
88 12 ▶ sub content_type { my $self = shift; $self->{headers}->content_type(@_) };
Subroutine content_type: called CC=1 SCAR=0.0
89 sub cookies {
90 7 ▶ my $self = shift;
Subroutine cookies: called CC=3 SCAR=11.8
91 7 ▶ $self->{cookies} ||= do {
Condition66%2/3
$self->{"cookies"} ||= do { if (my $header = $self->header("Cookie")) { +{"CGI::Simple::Cookie"->parse($header)}; } else { {}; } }
l!l&&r!l&&!r
160
MC/DC0%0/2
$self->{"cookies"} ||= do { if (my $header = $self->header("Cookie")) { +{"CGI::Simple::Cookie"->parse($header)}; } else { {}; } }
$self->{"cookies"} do { if (my $header = $self->header("Cookie")) { +{"CGI::Simple::Cookie"->parse($header)}; } else { {}; } }
Truth table66%2/3
A ||= B
A= $self->{"cookies"}B= do { if (my $header = $self->header("Cookie")) { +{"CGI::Simple::Cookie"->parse($header)}; } else { {}; } }
ABresult
1X1
011
000
92 6 ▶ if (my $header = $self->header('Cookie')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $header = $self->header('Cookie')) { } 0 6 6
93 0 +{ CGI::Simple::Cookie->parse($header) };
94 } else {
95 6 +{};
96 }
97 }
98 }
99 }
100  
101 {
102 1 package # hide from pause
103 HTTP::Engine::Request;
104  
105 sub new {
106 6 ▶ my ($class, ) = @_;
Subroutine new: called CC=1 SCAR=0.0
107 6 bless { }, $class;
108 }
109  
110 0 ▶ sub hostname { $ENV{HTTP_HOST} || $ENV{SERVER_HOST} }
Subroutine hostname: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"HTTP_HOST"} or $ENV{"SERVER_HOST"} 0 0 0
111 0 ▶ sub protocol { $ENV{SERVER_PROTOCOL} || 'HTTP/1.0' }
Subroutine protocol: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"SERVER_PROTOCOL"} or "HTTP/1.0" 0 0 0
112 12 ▶ sub method { $ENV{HTTP_METHOD} || 'GET' }
Subroutine method: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"HTTP_METHOD"} or "GET" 12 0 12
113  
114 sub param {
115 1 ▶ my $self = shift;
Subroutine param: called CC=2 SCAR=7.6
116 1 ▶ $self->{cs} ||= CGI::Simple->new();
Condition33%1/3
$self->{"cs"} ||= "CGI::Simple"->new
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"cs"} ||= "CGI::Simple"->new
$self->{"cs"} "CGI::Simple"->new
Truth table33%1/3
A ||= B
A= $self->{"cs"}B= "CGI::Simple"->new
ABresult
1X1
011
000
117 1 $self->{cs}->param(@_);
118 }
119 sub upload {
120 0 ▶ my $self = shift;
Subroutine upload: not called CC=2 SCAR=17.9
121 0 ▶ $self->{cs} ||= CGI::Simple->new();
Condition0%0/3
$self->{"cs"} ||= "CGI::Simple"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"cs"} ||= "CGI::Simple"->new
$self->{"cs"} "CGI::Simple"->new
Truth table0%0/3
A ||= B
A= $self->{"cs"}B= "CGI::Simple"->new
ABresult
1X1
011
000
122 0 $self->{cs}->upload(@_);
123 }
124 sub header {
125 2 ▶ my ($self, $key) = @_;
Subroutine header: called CC=2 SCAR=7.0
126 2 $key = uc $key;
127 2 $key =~ s/-/_/;
128 2 ▶ $ENV{'HTTP_' . $key} || $ENV{'HTTPS_' . $key};
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'HTTP_' . $key} or $ENV{'HTTPS_' . $key} 0 2 2
129 }
130 }
131  
132 1 1;
133  
134 __END__
« Engine/Role/RequestBuilder/Standard.pm ↑ Summary Engine/Interface/ModPerl.pm »