Net/Async/FastCGI/Protocol.pm

filter: Statementstmt 100% 39 / 39 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 33.3% 1 / 3 totaltotal 93.1% 54 / 58 CC 5 SCAR 9.8
CC
5
Cov
96%
on_read
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
« Net/Async/FastCGI/ServerProtocol.pm ↑ Summary Net/Async/FastCGI.pm »
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, 2010-2024 -- leonerd@leonerd.org.uk
5  
6 package Net::Async::FastCGI::Protocol 0.26;
7  
8 18 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 18 ▶use base qw( IO::Async::Protocol::Stream );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 18 ▶use Net::FastCGI::Constant qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
14 FCGI_UNKNOWN_TYPE
15 18 );
16  
17 18 ▶use Net::FastCGI::Protocol qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
18 parse_header
19 build_record
20 build_unknown_type_body
21 18 );
22  
23 sub on_read
24 103 ▶{
Subroutine on_read: called CC=5 SCAR=16.1
Pod documented
25 103 my $self = shift;
26 103 my ( $buffref, $handleclosed ) = @_;
27  
28 103 my $blen = length $$buffref;
29  
30 103 ▶ if( $handleclosed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handleclosed) 1 102 103
31 # Abort
32 1 my $fcgi = $self->{fcgi};
33 1 $fcgi->remove_child( $self );
34 1 return;
35 }
36  
37 # Do we have a record header yet?
38 102 ▶ return 0 unless( $blen >= 8 );
Branch: 1 branch
BranchTrueFalseTotal
unless $blen >= 8 0 102 102
39  
40 # Excellent - parse it
41 102 my ( $type, $reqid, $contentlen, $padlen ) = parse_header( $$buffref );
42  
43 # Do we have enough for a complete record?
44 102 ▶ return 0 unless( $blen >= 8 + $contentlen + $padlen );
Branch: 1 branch
BranchTrueFalseTotal
unless $blen >= 8 + $contentlen + $padlen 0 102 102
45  
46 102 substr( $$buffref, 0, 8, "" ); # Header
47  
48 102 my $rec = {
49 type => $type,
50 reqid => $reqid,
51 len => $contentlen,
52 plen => $padlen,
53 };
54  
55 102 $rec->{content} = substr( $$buffref, 0, $contentlen, "" );
56  
57 102 substr( $$buffref, 0, $rec->{plen}, "" ); # Padding
58  
59 102 ▶ if( $reqid == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reqid == 0) { } 4 98 102
60 4 $self->on_mgmt_record( $type, $rec );
61 }
62 else {
63 98 $self->on_record( $reqid, $rec );
64 }
65  
66 102 return 1;
67 }
68  
69 sub on_mgmt_record
70 1 ▶{
Subroutine on_mgmt_record: called CC=1 SCAR=0.0
Pod undocumented
71 1 my $self = shift;
72 1 my ( $type, $rec ) = @_;
73  
74 1 $self->write_record( { type => FCGI_UNKNOWN_TYPE, reqid => 0 }, build_unknown_type_body( $type ) );
75 }
76  
77 sub write_record
78 71 ▶{
Subroutine write_record: called CC=1 SCAR=0.0
Pod undocumented
79 71 my $self = shift;
80 71 my ( $rec, $content ) = @_;
81  
82 71 $self->write( build_record( $rec->{type}, $rec->{reqid}, $content ) );
83 }
84  
85 18 0x55AA;
« Net/Async/FastCGI/ServerProtocol.pm ↑ Summary Net/Async/FastCGI.pm »