blib/lib/Net/Async/HTTP/Server/Protocol.pm

filter: Statementstmt 96.2% 51 / 53 Branchbran 81.2% 13 / 16 Conditioncond 50.0% 4 / 8 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 87.1% 81 / 93 SCAR 25.9
CC
13
Cov
88%
on_read
7.4
_flush_requests
4.0
on_closed
3.0
CRAP 13.3
« blib/lib/Net/Async/HTTP/Server/Request.pm ↑ Summary Build »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2013-2015 -- leonerd@leonerd.org.uk
5  
6 package Net::Async::HTTP::Server::Protocol;
7  
8 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use base qw( IO::Async::Stream );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 12 our $VERSION = '0.13';
13  
14 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 12 ▶use Scalar::Util qw( weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 12 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 12 my $CRLF = "\x0d\x0a";
20  
21 sub on_read
22 {
23 54 ▶ my $self = shift;
Subroutine on_read: called CC=7 SCAR=20.0
Pod documented
24 54 my ( $buffref, $eof ) = @_;
25  
26 54 ▶ return 0 if $eof;
Branch: 1 branch
BranchTrueFalseTotal
if $eof 6 48 54
27  
28 48 ▶ return 0 unless $$buffref =~ s/^(.*?$CRLF$CRLF)//s;
Branch: 1 branch
BranchTrueFalseTotal
unless $$buffref =~ s/^(.*?$CRLF$CRLF)//s 23 25 48
29 25 my $header = $1;
30  
31 25 my $request = HTTP::Request->parse( $header );
32 25 ▶ unless( $request and defined $request->protocol and $request->protocol =~ m/^HTTP/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($request and defined $request->protocol and $request->protocol =~ /^HTTP/) 0 25 25
Condition33%2/6
$request and defined $request->protocol and $request->protocol =~ /^HTTP/
!ll&&!rl&&r
0025
$request and defined $request->protocol
!ll&&!rl&&r
0025
MC/DC0%0/3
$request and defined $request->protocol and $request->protocol =~ /^HTTP/
$request defined $request->protocol $request->protocol =~ /^HTTP/
Truth table25%1/4
A and B and C
A= $requestB= defined $request->protocolC= $request->protocol =~ /^HTTP/
ABCresult
0XX0
10X0
1100
1111
33 0 $self->close_now;
34 0 return 0;
35 }
36  
37 25 ▶ my $request_body_len = $request->content_length || 0;
Condition100%2/2
$request->content_length || 0
l!l
322
MC/DC100%1/1
$request->content_length || 0
$request->content_length
Truth table100%2/2
A
A= $request->content_length
Aresult
11
00
38  
39 25 $self->debug_printf( "REQUEST %s %s", $request->method, $request->uri->path );
40  
41 return sub {
42 26 ▶ my ( undef, $buffref, $eof ) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
43  
44 26 ▶ return 0 unless length($$buffref) >= $request_body_len;
Branch: 1 branch
BranchTrueFalseTotal
unless length $$buffref >= $request_body_len 2 24 26
45  
46 24 $request->add_content( substr( $$buffref, 0, $request_body_len, "" ) );
47  
48 24 push @{ $self->{requests} }, my $req = $self->parent->make_request( $self, $request );
49 24 weaken( $self->{requests}[-1] );
50  
51 24 $self->parent->_received_request( $req );
52  
53 24 return undef;
54 25 };
55 }
56  
57 sub on_closed
58 {
59 8 ▶ my $self = shift;
Subroutine on_closed: called CC=3 SCAR=11.1
Pod documented
60  
61 8 ▶ $_ and $_->_close for @{ $self->{requests} };
Branch: 1 branch
BranchTrueFalseTotal
$_ and $_->_close 1 0 1
62 8 undef @{ $self->{requests} };
63 }
64  
65 sub _flush_requests
66 {
67 58 ▶ my $self = shift;
Subroutine _flush_requests: called CC=4 SCAR=13.9
68  
69 58 my $queue = $self->{requests};
70 58 ▶ while( @$queue ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$queue) 59 19 78
71 59 my $req = $queue->[0];
72 59 ▶ $req or shift @$queue, next;
Branch: 1 branch
BranchTrueFalseTotal
$req or shift @$queue, next 0 59 59
73  
74 59 my $is_done = $req->_write_to_stream( $self );
75  
76 59 ▶ $is_done ? shift @$queue : return;
Branch: 1 branch
BranchTrueFalseTotal
$is_done ? : 20 39 59
77 }
78 }
79  
80 12 0x55AA;
« blib/lib/Net/Async/HTTP/Server/Request.pm ↑ Summary Build »