| 1 | package Unblock::HTTP1::Transaction; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 32 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 32 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 32 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 32 | ▶ | use Scalar::Util qw(weaken blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 32 | ▶ | use Uniform::HTTP::Response; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 32 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 158 | ▶ | sub _new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=7 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 158 | my ($class, $owner, $request, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 13 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||
| 14 | owner => $owner, | ||||||||||||||||||||||||||||||||||||||||||
| 15 | request => $request, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | response => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | state => 'active', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | error => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | callbacks => $args{callbacks} || {}, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | local_done => $args{local_done} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | remote_done => $args{remote_done} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | send_plan => $args{send_plan}, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 158 | ▶ | blocked => 0, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$args{'callbacks'} || {}
MC/DC0%0/1
$args{'callbacks'} || {}
$args{'callbacks'}
Truth table50%1/2
A
A= $args{'callbacks'}
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 158 | $self->{receive_body} = $owner->{receive_body}; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 158 | $self->{max_buffered_body_bytes} = $owner->{max_buffered_body_bytes}; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 158 | my $on_data = delete $self->{callbacks}{on_data}; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 158 | ▶ | $self->on_data($on_data) if $on_data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | croak 'buffered reception cannot be combined with on_body' | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 158 | ▶ | if $self->{receive_body} eq 'buffered' && $self->{callbacks}{on_body}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"receive_body"} eq "buffered" and $self->{"callbacks"}{"on_body"}
MC/DC0%0/2
$self->{"receive_body"} eq "buffered" and $self->{"callbacks"}{"on_body"}
$self->{"receive_body"} eq "buffered"
$self->{"callbacks"}{"on_body"}
Truth table66%2/3
A and B
A= $self->{"receive_body"} eq "buffered"B= $self->{"callbacks"}{"on_body"}
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 158 | weaken($self->{owner}); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 158 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 221 | ▶ | sub request { $_[0]{request} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 107 | ▶ | sub response { $_[0]{response} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 52 | ▶ | sub state { $_[0]{state} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
state: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 8 | ▶ | sub error { $_[0]{error} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 40 | ▶ | sub is_complete { $_[0]{state} eq 'complete' ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_complete: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | ▶ | sub is_cancelled { $_[0]{state} eq 'cancelled' ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_cancelled: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | sub is_error { $_[0]{state} eq 'error' ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_error: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 750 | ▶ | sub is_terminal { $_[0]{state} ne 'active' ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_terminal: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 11 | ▶ | sub on_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_data: called CC=9 SCAR=24.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 11 | my ($self, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 11 | ▶ | croak 'on_data(): callback must be a coderef' unless ref($cb) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | croak 'on_data(): receive body has already started or finished' | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 11 | ▶ | if $self->{receive_started} || $self->{receive_done} || $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->{"receive_started"} or $self->{"receive_done"} or $self->is_terminal
$self->{"receive_started"} or $self->{"receive_done"}
MC/DC33%1/3
$self->{"receive_started"} or $self->{"receive_done"} or $self->is_terminal
$self->{"receive_started"}
$self->{"receive_done"}
$self->is_terminal
Truth table50%2/4
A or B or C
A= $self->{"receive_started"}B= $self->{"receive_done"}C= $self->is_terminal
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 9 | my $owner = $self->{owner}; | |||||||||||||||||||||||||||||||||||||||||
| 50 | croak 'on_data(): cannot be combined with on_body' | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 9 | ▶ | if $self->{callbacks}{on_body} || ($owner && $owner->{callbacks}{on_body}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->{"callbacks"}{"on_body"} or $owner and $owner->{"callbacks"}{"on_body"}
$owner and $owner->{"callbacks"}{"on_body"}
MC/DC0%0/3
$self->{"callbacks"}{"on_body"} or $owner and $owner->{"callbacks"}{"on_body"}
$self->{"callbacks"}{"on_body"}
$owner
$owner->{"callbacks"}{"on_body"}
Truth table25%1/4
A or B and C
A= $self->{"callbacks"}{"on_body"}B= $ownerC= $owner->{"callbacks"}{"on_body"}
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 9 | ▶ | croak 'on_data(): callback is already registered' if $self->{callbacks}{on_data}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 9 | $self->{callbacks}{on_data} = $cb; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 9 | $self->{receive_body} = 'stream'; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 44 | ▶ | sub on_finish { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_finish: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 44 | my ($self, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 44 | ▶ | croak 'on_finish(): callback must be a coderef' unless ref($cb) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 44 | ▶ | croak 'on_finish(): Transaction is terminal' if $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 28 | ▶ | croak 'on_finish(): callback is already registered' if $self->{callbacks}{on_finish}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 28 | $self->{callbacks}{on_finish} = $cb; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 28 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 74 | ▶ | sub _receive_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_receive_data: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 74 | my ($self, $message, $bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 74 | ▶ | return 1 if $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 74 | $self->{receive_started} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 74 | ▶ | if ($self->{receive_body} eq 'buffered') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 14 | ▶ | my $size = ($self->{received_bytes} || 0) + length($bytes); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'received_bytes'} || 0
MC/DC100%1/1
$self->{'received_bytes'} || 0
$self->{'received_bytes'}
Truth table100%2/2
A
A= $self->{'received_bytes'}
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 14 | ▶ | if ($size > $self->{max_buffered_body_bytes}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | delete $self->{receive_chunks}; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | delete $self->{received_bytes}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | return 'received body exceeds max_buffered_body_bytes'; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 13 | push @{ $self->{receive_chunks} }, $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 13 | $self->{received_bytes} = $size; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 13 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 60 | ▶ | return $self->_invoke('on_data', $bytes) if $self->{callbacks}{on_data}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 55 | my $owner = $self->{owner}; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 55 | ▶ | return $owner->_invoke_server('on_body', $self, $message, $bytes) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$owner and $owner->can("_invoke_server")
MC/DC50%1/2
$owner and $owner->can("_invoke_server")
$owner
$owner->can("_invoke_server")
Truth table66%2/3
A and B
A= $ownerB= $owner->can("_invoke_server")
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | if $owner && $owner->can('_invoke_server'); | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 36 | return $self->_invoke('on_body', $message, $bytes); | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 114 | ▶ | sub _finish_receive { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish_receive: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 114 | my ($self, $message) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 114 | $self->{receive_done} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 114 | ▶ | if ($self->{receive_body} eq 'buffered' && $message->body_is_mutable) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"receive_body"} eq "buffered" and $message->body_is_mutable
MC/DC100%2/2
$self->{"receive_body"} eq "buffered" and $message->body_is_mutable
$self->{"receive_body"} eq "buffered"
$message->body_is_mutable
Truth table100%3/3
A and B
A= $self->{"receive_body"} eq "buffered"B= $message->body_is_mutable
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 9 | ▶ | $message->body(join '', @{ delete($self->{receive_chunks}) || [] }); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $self->{'receive_chunks'} || []
MC/DC100%1/1
delete $self->{'receive_chunks'} || []
delete $self->{'receive_chunks'}
Truth table100%2/2
A
A= delete $self->{'receive_chunks'}
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 114 | delete $self->{receive_chunks}; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 114 | delete $self->{received_bytes}; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 114 | return; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 158 | ▶ | sub _notify_finish { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_notify_finish: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 158 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 158 | ▶ | return unless $self->is_terminal && !$self->{finish_called}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->is_terminal and not $self->{"finish_called"}
MC/DC0%0/2
$self->is_terminal and not $self->{"finish_called"}
$self->is_terminal
not $self->{"finish_called"}
Truth table33%1/3
A and not(B)
A= $self->is_terminalB= not $self->{"finish_called"}
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 158 | $self->{finish_pending} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 158 | ▶ | return if $self->{callback_depth}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 153 | $self->{finish_called} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 153 | delete $self->{finish_pending}; | |||||||||||||||||||||||||||||||||||||||||
| 107 | # Terminal observers cannot undo cleanup or recursively report an error. | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 153 | $self->_invoke('on_finish'); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 153 | return; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 11 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 11 | my ($self, $bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 11 | ▶ | croak 'write(): Transaction is terminal' if $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 10 | ▶ | my $owner = $self->{owner} or croak 'write(): HTTP/1 connection is gone'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 10 | return $owner->_transaction_write($self, $bytes, 0); | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 7 | ▶ | sub end { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end: called CC=4 SCAR=14.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 7 | my ($self, $bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 7 | ▶ | croak 'end(): Transaction is terminal' if $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | ▶ | my $owner = $self->{owner} or croak 'end(): HTTP/1 connection is gone'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 7 | ▶ | return $owner->_transaction_write($self, defined($bytes) ? $bytes : '', 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 78 | ▶ | sub respond { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
respond: called CC=12 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 78 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 78 | ▶ | croak 'respond(): Transaction is terminal' if $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 78 | ▶ | my $owner = $self->{owner} or croak 'respond(): HTTP/1 connection is gone'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 78 | my ($response, %option); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 78 | ▶ | if (@arg && ref($arg[0])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@arg and ref $arg[0]
MC/DC50%1/2
@arg and ref $arg[0]
@arg
ref $arg[0]
Truth table66%2/3
A and B
A= @argB= ref $arg[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 41 | $response = shift @arg; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 41 | ▶ | croak 'respond(): requires a Uniform HTTP response object' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
builtin::blessed($response) and $response->can("status") and $response->can("header_count")
builtin::blessed($response) and $response->can("status")
MC/DC33%1/3
builtin::blessed($response) and $response->can("status") and $response->can("header_count")
builtin::blessed($response)
$response->can("status")
$response->can("header_count")
Truth table50%2/4
A and B and C
A= builtin::blessed($response)B= $response->can("status")C= $response->can("header_count")
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | unless blessed($response) && $response->can('status') | ||||||||||||||||||||||||||||||||||||||||||
| 136 | && $response->can('header_count'); | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 40 | ▶ | croak 'respond(): options must be key/value pairs' if @arg % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 40 | %option = @arg; | |||||||||||||||||||||||||||||||||||||||||
| 139 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 37 | ▶ | croak 'respond(): response fields must be key/value pairs' if @arg % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 37 | my %field = @arg; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 37 | for my $name (qw(stream_body on_drain)) { | |||||||||||||||||||||||||||||||||||||||||
| 143 | 74 | ▶ | $option{$name} = delete $field{$name} if exists $field{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 37 | $response = Uniform::HTTP::Response->new(%field); | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 77 | return $owner->_transaction_respond($self, $response, %option); | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 5 | ▶ | sub send_informational { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_informational: called CC=10 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 5 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 5 | ▶ | croak 'send_informational(): Transaction is terminal' if $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 5 | ▶ | my $owner = $self->{owner} or croak 'send_informational(): HTTP/1 connection is gone'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 5 | my $response; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 5 | ▶ | if (@arg && ref($arg[0])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@arg and ref $arg[0]
MC/DC50%1/2
@arg and ref $arg[0]
@arg
ref $arg[0]
Truth table66%2/3
A and B
A= @argB= ref $arg[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | ▶ | croak 'send_informational(): response object does not take options' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | unless @arg == 1; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 3 | $response = $arg[0]; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 3 | ▶ | croak 'send_informational(): requires a Uniform HTTP response object' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
builtin::blessed($response) and $response->can("status") and $response->can("header_count")
builtin::blessed($response) and $response->can("status")
MC/DC33%1/3
builtin::blessed($response) and $response->can("status") and $response->can("header_count")
builtin::blessed($response)
$response->can("status")
$response->can("header_count")
Truth table50%2/4
A and B and C
A= builtin::blessed($response)B= $response->can("status")C= $response->can("header_count")
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | unless blessed($response) && $response->can('status') | ||||||||||||||||||||||||||||||||||||||||||
| 163 | && $response->can('header_count'); | ||||||||||||||||||||||||||||||||||||||||||
| 164 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | ▶ | croak 'send_informational(): response fields must be key/value pairs' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | if @arg % 2; | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | $response = Uniform::HTTP::Response->new(@arg); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | return $owner->_transaction_informational($self, $response); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 28 | ▶ | sub cancel { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cancel: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 28 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 28 | ▶ | return $self if $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 9 | my $owner = $self->{owner}; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 9 | ▶ | if ($owner) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 9 | $owner->_transaction_cancel($self); | |||||||||||||||||||||||||||||||||||||||||
| 179 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $self->_mark_cancelled; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $self->_notify_finish; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 9 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 124 | ▶ | sub _set_response { $_[0]{response} = $_[1]; return $_[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_response: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 81 | ▶ | sub _mark_local_done { $_[0]{local_done} = 1; return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mark_local_done: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 114 | ▶ | sub _mark_remote_done { $_[0]{remote_done} = 1; return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mark_remote_done: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 108 | ▶ | sub _mark_complete { $_[0]{state} = 'complete'; return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mark_complete: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 9 | ▶ | sub _mark_cancelled { $_[0]->_discard_receive; $_[0]{state} = 'cancelled'; return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mark_cancelled: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 36 | ▶ | sub _fail { $_[0]->_discard_receive; $_[0]{state} = 'error'; $_[0]{error} = $_[1]; return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fail: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 45 | ▶ | sub _discard_receive { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_discard_receive: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 45 | delete $_[0]{receive_chunks}; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 45 | delete $_[0]{received_bytes}; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 45 | return; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 310 | ▶ | sub _invoke { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_invoke: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 310 | my ($self, $name, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 310 | ▶ | my $cb = $self->{callbacks}{$name} or return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 139 | $self->{callback_depth}++; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 139 | my $ok = eval { $cb->($self, @args); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 139 | my $error = "$@"; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 139 | $self->{callback_depth}--; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 139 | ▶ | $self->_notify_finish if $self->{finish_pending}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 139 | ▶ | return $ok ? 1 : $error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 32 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | __END__ | ||||||||||||||||||||||||||||||||||||||||||