Perlbal/ChunkedUploadState.pm

filter: Statementstmt 94.4% 34 / 36 Branchbran 83.3% 15 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 4 totaltotal 79.7% 55 / 69 CC 12 SCAR 15.4
CC
12
Cov
88%
drive_machine
7.0
new
4.3
on_readable
3.2
CRAP 4.6
« Perlbal/Plugin/Redirect.pm ↑ Summary Perlbal/Plugin/EchoService.pm »
1 package Perlbal::ChunkedUploadState;
2 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 ▶sub new {
Subroutine new: called CC=4 SCAR=14.6
Pod undocumented
5 3 my ($pkg, %args) = @_;
6 3 my $self = bless {
7 'buf' => '',
8 'bytes_remain' => 0, # remaining in chunk (ignoring final 2 byte CRLF)
9 }, $pkg;
10 3 foreach my $k (qw(on_new_chunk on_disconnect on_zero_chunk)) {
11 9 ▶ $self->{$k} = (delete $args{$k}) || sub {};
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
delete $args{$k} || sub { }
l!l&&r!l&&!r
900
MC/DC0%0/2
delete $args{$k} || sub { }
delete $args{$k} sub { }
Truth table33%1/3
A || B
A= delete $args{$k}B= sub { }
ABresult
1X1
011
000
12 }
13 3 ▶ die "bogus args" if %args;
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 3 3
14 3 return $self;
15 }
16  
17 17 ▶sub on_readable {
Subroutine on_readable: called CC=3 SCAR=11.6
Pod undocumented
18 17 my ($self, $ds) = @_;
19 17 my $rbuf = $ds->read(131072);
20 17 ▶ unless (defined $rbuf) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rbuf) 0 17 17
21 0 $self->{on_disconnect}->();
22 0 return;
23 }
24  
25 17 $self->{buf} .= $$rbuf;
26  
27 17 ▶ while ($self->drive_machine) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->drive_machine) 40 17 57
28 }
29  
30 # returns 1 if progress was made parsing buffer
31 57 ▶sub drive_machine {
Subroutine drive_machine: called CC=7 SCAR=19.5
Pod undocumented
32 57 my $self = shift;
33  
34 57 my $buflen = length($self->{buf});
35 57 ▶ return 0 unless $buflen;
Branch: 1 branch
BranchTrueFalseTotal
unless $buflen 8 49 57
36  
37 49 ▶ if (my $br = $self->{bytes_remain}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $br = $self->{"bytes_remain"}) 24 25 49
38 24 ▶ my $extract = $buflen > $br ? $br : $buflen;
Branch: 1 branch
BranchTrueFalseTotal
$buflen > $br ? : 16 8 24
39 24 my $ch = substr($self->{buf}, 0, $extract, '');
40 24 $self->{bytes_remain} -= $extract;
41 24 ▶ die "assert" if $self->{bytes_remain} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"bytes_remain"} < 0 0 24 24
42 24 $self->{on_new_chunk}->(\$ch);
43 24 return 1;
44 }
45  
46 25 ▶ return 0 unless $self->{buf} =~ s/^(?:\r\n)?([0-9a-fA-F]+)(?:;.*)?\r\n//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"buf"} =~ s/^(?:\r\n)?([0-9a-fA-F]+)(?:;.*)?\r\n// 6 19 25
47 19 $self->{bytes_remain} = hex($1);
48  
49 19 ▶ if ($self->{bytes_remain} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bytes_remain"} == 0) 3 16 19
50 # FIXME: new state machine state for trailer parsing/discarding.
51 # (before we do on_zero_chunk). for now, though, just assume
52 # no trailers and throw away the extra post-trailer \r\n that
53 # is probably in this packet. hacky.
54 3 $self->{buf} =~ s/^\r\n//;
55 3 $self->{hit_zero} = 1;
56 3 $self->{on_zero_chunk}->();
57 3 return 0;
58 }
59 16 return 1;
60 }
61  
62 12 ▶sub hit_zero_chunk { $_[0]{hit_zero} }
Subroutine hit_zero_chunk: called CC=1 SCAR=0.0
Pod undocumented
63  
64 22 1;
« Perlbal/Plugin/Redirect.pm ↑ Summary Perlbal/Plugin/EchoService.pm »