| 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 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 7 | my $class = shift; | |||||||||||||||||||||||||||
| 13 | 7 | bless { @_ }, $class; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 7 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 7 | my ($self, ) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | ### run handler | ||||||||||||||||||||||||||||
| 20 | 7 | my $req = HTTP::Engine::Request->new(); | |||||||||||||||||||||||||||
| 21 | 7 | my $res = $self->{request_handler}->( $req ); | |||||||||||||||||||||||||||
| 22 | 7 | ▶ | unless ( Scalar::Util::blessed($res) && $res->isa('HTTP::Engine::Response') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($res) and $res->isa("HTTP::Engine::Response")
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")
| |||||||||||||||||||||||||||||
| 23 | 0 | die "You should return instance of HTTP::Engine::Response."; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 7 | HTTP::Engine::ResponseFinalizer->finalize($req => $res); | |||||||||||||||||||||||||||
| 26 | 7 | 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 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||
| 39 | 7 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 40 | 7 | ▶ | unless (Scalar::Util::blessed($args{interface})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 7 | ▶ | if ($args{interface}->{module} ne 'MinimalCGI') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 7 | ); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 7 | bless { interface => $args{interface} }, $class; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 7 | ▶ | 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 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 7 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 61 | 7 | bless { | |||||||||||||||||||||||||||
| 62 | status => 200, | ||||||||||||||||||||||||||||
| 63 | body => '', | ||||||||||||||||||||||||||||
| 64 | headers => HTTP::Headers::Fast->new(), | ||||||||||||||||||||||||||||
| 65 | %args, | ||||||||||||||||||||||||||||
| 66 | }, $class; | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 16 | ▶ | sub header { | ||||||||||||||||||||||||||
|
Subroutine
header: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 69 | 16 | my $self = shift; | |||||||||||||||||||||||||||
| 70 | 16 | $self->{headers}->header(@_); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 8 | ▶ | sub headers { | ||||||||||||||||||||||||||
|
Subroutine
headers: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 74 | 8 | $self->{headers}; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 14 | ▶ | sub status { | ||||||||||||||||||||||||||
|
Subroutine
status: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 77 | 14 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | 14 | ▶ | $self->{status} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 14 | $self->{status}; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 35 | ▶ | sub body { | ||||||||||||||||||||||||||
|
Subroutine
body: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 82 | 35 | my $self = shift; | |||||||||||||||||||||||||||
| 83 | 35 | ▶ | $self->{body} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 35 | $self->{body}; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 21 | ▶ | sub protocol { 'HTTP/1.0' }; | ||||||||||||||||||||||||||
|
Subroutine
protocol: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | 7 | ▶ | sub content_length { my $self = shift; $self->{headers}->content_length(@_) }; | ||||||||||||||||||||||||||
|
Subroutine
content_length: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | 14 | ▶ | sub content_type { my $self = shift; $self->{headers}->content_type(@_) }; | ||||||||||||||||||||||||||
|
Subroutine
content_type: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | 8 | ▶ | sub cookies { | ||||||||||||||||||||||||||
|
Subroutine
cookies: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||
| 90 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 91 | 8 | ▶ | $self->{cookies} ||= do { | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"cookies"} ||= do {
if (my $header = $self->header("Cookie")) {
+{"CGI::Simple::Cookie"->parse($header)};
}
else {
{};
}
}
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 {
{};
}
}
| |||||||||||||||||||||||||||||
| 92 | 7 | ▶ | if (my $header = $self->header('Cookie')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | +{ CGI::Simple::Cookie->parse($header) }; | |||||||||||||||||||||||||||
| 94 | } else { | ||||||||||||||||||||||||||||
| 95 | 7 | +{}; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||
| 102 | 1 | package # hide from pause | |||||||||||||||||||||||||||
| 103 | HTTP::Engine::Request; | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 106 | 7 | my ($class, ) = @_; | |||||||||||||||||||||||||||
| 107 | 7 | 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
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub protocol { $ENV{SERVER_PROTOCOL} || 'HTTP/1.0' } | ||||||||||||||||||||||||||
|
Subroutine
protocol: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 15 | ▶ | sub method { $ENV{REQUEST_METHOD} || 'GET' } | ||||||||||||||||||||||||||
|
Subroutine
method: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 1 | ▶ | sub param { | ||||||||||||||||||||||||||
|
Subroutine
param: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 115 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 116 | 1 | ▶ | $self->{cs} ||= CGI::Simple->new(); | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"cs"} ||= "CGI::Simple"->new
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
| |||||||||||||||||||||||||||||
| 117 | 1 | $self->{cs}->param(@_); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub upload { | ||||||||||||||||||||||||||
|
Subroutine
upload: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 120 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | $self->{cs} ||= CGI::Simple->new(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"cs"} ||= "CGI::Simple"->new
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
| |||||||||||||||||||||||||||||
| 122 | 0 | $self->{cs}->upload(@_); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | 2 | ▶ | sub header { | ||||||||||||||||||||||||||
|
Subroutine
header: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 125 | 2 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 126 | 2 | $key = uc $key; | |||||||||||||||||||||||||||
| 127 | 2 | $key =~ s/-/_/; | |||||||||||||||||||||||||||
| 128 | 2 | ▶ | $ENV{'HTTP_' . $key} || $ENV{'HTTPS_' . $key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 1 | 1; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | __END__ | ||||||||||||||||||||||||||||