| 1 | package Linux::Event::HTTP::Body::Stream; | ||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 10 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 32 | ▶ | sub _validated_options ($kind, %option) { | ||||||||||||||||||||||||||
|
Subroutine
_validated_options: called CC=8 SCAR=21.1
| |||||||||||||||||||||||||||||
| 11 | 32 | ▶ | die 'body stream kind must be request or response' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$kind ne "request" and $kind ne "response"
MC/DC0%0/2
$kind ne "request" and $kind ne "response"
$kind ne "request"
$kind ne "response"
Truth table66%2/3
A and B
A= $kind ne "request"B= $kind ne "response"
| |||||||||||||||||||||||||||||
| 12 | if $kind ne 'request' && $kind ne 'response'; | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 32 | my $on_drain = delete $option{on_drain}; | |||||||||||||||||||||||||||
| 15 | 32 | my $on_cancel = delete $option{on_cancel}; | |||||||||||||||||||||||||||
| 16 | 32 | my $operation = $kind . '_body'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 32 | ▶ | die "$operation(): on_drain must be a coderef" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $on_drain and ref $on_drain ne "CODE"
MC/DC100%2/2
defined $on_drain and ref $on_drain ne "CODE"
defined $on_drain
ref $on_drain ne "CODE"
Truth table100%3/3
A and B
A= defined $on_drainB= ref $on_drain ne "CODE"
| |||||||||||||||||||||||||||||
| 19 | if defined($on_drain) && ref($on_drain) ne 'CODE'; | ||||||||||||||||||||||||||||
| 20 | 30 | ▶ | die "$operation(): on_cancel must be a coderef" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $on_cancel and ref $on_cancel ne "CODE"
MC/DC0%0/2
defined $on_cancel and ref $on_cancel ne "CODE"
defined $on_cancel
ref $on_cancel ne "CODE"
Truth table66%2/3
A and B
A= defined $on_cancelB= ref $on_cancel ne "CODE"
| |||||||||||||||||||||||||||||
| 21 | if defined($on_cancel) && ref($on_cancel) ne 'CODE'; | ||||||||||||||||||||||||||||
| 22 | 30 | ▶ | die "$operation(): unknown option: " . join(', ', sort keys %option) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | if %option; | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 29 | return ($on_drain, $on_cancel); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 10 | ▶ | sub _validate_options ($class, $kind, %option) { | ||||||||||||||||||||||||||
|
Subroutine
_validate_options: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 10 | _validated_options($kind, %option); | |||||||||||||||||||||||||||
| 30 | 9 | return; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 22 | ▶ | sub _new ($class, $transaction, $kind, %option) { | ||||||||||||||||||||||||||
|
Subroutine
_new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 22 | my ($on_drain, $on_cancel) = _validated_options($kind, %option); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 20 | my $self = bless { | |||||||||||||||||||||||||||
| 37 | transaction => $transaction, | ||||||||||||||||||||||||||||
| 38 | kind => $kind, | ||||||||||||||||||||||||||||
| 39 | on_drain => $on_drain, | ||||||||||||||||||||||||||||
| 40 | on_cancel => $on_cancel, | ||||||||||||||||||||||||||||
| 41 | complete => 0, | ||||||||||||||||||||||||||||
| 42 | cancelled => 0, | ||||||||||||||||||||||||||||
| 43 | flow_blocked => 0, | ||||||||||||||||||||||||||||
| 44 | }, $class; | ||||||||||||||||||||||||||||
| 45 | 20 | weaken($self->{transaction}); | |||||||||||||||||||||||||||
| 46 | 20 | return $self; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 6 | ▶ | sub is_complete ($self) { !!$self->{complete} } | ||||||||||||||||||||||||||
|
Subroutine
is_complete: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 4 | ▶ | sub is_cancelled ($self) { !!$self->{cancelled} } | ||||||||||||||||||||||||||
|
Subroutine
is_cancelled: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 33 | ▶ | sub _assert_writable ($self, $operation) { | ||||||||||||||||||||||||||
|
Subroutine
_assert_writable: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 53 | die "$operation(): streaming body is already complete" | ||||||||||||||||||||||||||||
| 54 | 33 | ▶ | if $self->{complete}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | die "$operation(): streaming body was cancelled" | ||||||||||||||||||||||||||||
| 56 | 32 | ▶ | if $self->{cancelled}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | my $transaction = $self->{transaction} | ||||||||||||||||||||||||||||
| 58 | 31 | ▶ | or die "$operation(): HTTP Transaction is no longer available"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 31 | return $transaction; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 18 | ▶ | sub write ($self, $bytes) { | ||||||||||||||||||||||||||
|
Subroutine
write: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 18 | my $operation = $self->{kind} . '_body->write'; | |||||||||||||||||||||||||||
| 64 | 18 | my $transaction = $self->_assert_writable($operation); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # A protocol controller may discover and then relieve flow pressure while | ||||||||||||||||||||||||||||
| 67 | # _write_body() is still on the stack. Mark the provisional blocked state | ||||||||||||||||||||||||||||
| 68 | # first so a reentrant _drain() cannot be lost. A successful write clears | ||||||||||||||||||||||||||||
| 69 | # it; a false return leaves it set only if no drain already cleared it. | ||||||||||||||||||||||||||||
| 70 | 17 | $self->{flow_blocked} = 1; | |||||||||||||||||||||||||||
| 71 | 17 | my ($accepted, $ok, $error); | |||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 17 | local $@; | |||||||||||||||||||||||||||
| 74 | 17 | $ok = eval { | |||||||||||||||||||||||||||
| 75 | $accepted = $transaction->_write_body( | ||||||||||||||||||||||||||||
| 76 | 17 | $self->{kind}, $bytes, 0, $operation, | |||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||
| 78 | 16 | 1; | |||||||||||||||||||||||||||
| 79 | }; | ||||||||||||||||||||||||||||
| 80 | 17 | $error = $@; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 17 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 1 | $self->{flow_blocked} = 0; | |||||||||||||||||||||||||||
| 84 | 1 | die $error; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 16 | ▶ | $self->{flow_blocked} = 0 if $accepted; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 16 | return $accepted; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 15 | ▶ | sub complete ($self, $bytes = '') { | ||||||||||||||||||||||||||
|
Subroutine
complete: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 92 | 15 | my $operation = $self->{kind} . '_body->complete'; | |||||||||||||||||||||||||||
| 93 | 15 | my $transaction = $self->_assert_writable($operation); | |||||||||||||||||||||||||||
| 94 | $transaction->_write_body( | ||||||||||||||||||||||||||||
| 95 | 14 | $self->{kind}, $bytes, 1, $operation, | |||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||
| 97 | 13 | $self->{complete} = 1; | |||||||||||||||||||||||||||
| 98 | 13 | $self->{flow_blocked} = 0; | |||||||||||||||||||||||||||
| 99 | 13 | return $self; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 1 | ▶ | sub _block ($self) { | ||||||||||||||||||||||||||
|
Subroutine
_block: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||
| 103 | 1 | ▶ | return if $self->{complete} || $self->{cancelled}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"complete"} or $self->{"cancelled"}
MC/DC0%0/2
$self->{"complete"} or $self->{"cancelled"}
$self->{"complete"}
$self->{"cancelled"}
Truth table33%1/3
A or B
A= $self->{"complete"}B= $self->{"cancelled"}
| |||||||||||||||||||||||||||||
| 104 | 1 | $self->{flow_blocked} = 1; | |||||||||||||||||||||||||||
| 105 | 1 | return; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 5 | ▶ | sub _drain ($self) { | ||||||||||||||||||||||||||
|
Subroutine
_drain: called CC=5 SCAR=17.0
| |||||||||||||||||||||||||||||
| 109 | 5 | ▶ | return if $self->{complete} || $self->{cancelled}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"complete"} or $self->{"cancelled"}
MC/DC0%0/2
$self->{"complete"} or $self->{"cancelled"}
$self->{"complete"}
$self->{"cancelled"}
Truth table33%1/3
A or B
A= $self->{"complete"}B= $self->{"cancelled"}
| |||||||||||||||||||||||||||||
| 110 | 5 | ▶ | return if !$self->{flow_blocked}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 3 | $self->{flow_blocked} = 0; | |||||||||||||||||||||||||||
| 112 | 3 | ▶ | my $callback = $self->{on_drain} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 3 | $callback->($self); | |||||||||||||||||||||||||||
| 114 | 3 | return; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 8 | ▶ | sub _cancel ($self) { | ||||||||||||||||||||||||||
|
Subroutine
_cancel: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 118 | 8 | ▶ | return if $self->{complete} || $self->{cancelled}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"complete"} or $self->{"cancelled"}
MC/DC50%1/2
$self->{"complete"} or $self->{"cancelled"}
$self->{"complete"}
$self->{"cancelled"}
Truth table66%2/3
A or B
A= $self->{"complete"}B= $self->{"cancelled"}
| |||||||||||||||||||||||||||||
| 119 | 5 | $self->{cancelled} = 1; | |||||||||||||||||||||||||||
| 120 | 5 | $self->{flow_blocked} = 0; | |||||||||||||||||||||||||||
| 121 | 5 | ▶ | my $callback = $self->{on_cancel} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 3 | $callback->($self); | |||||||||||||||||||||||||||
| 123 | 3 | return; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 10 | 1; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||