| 1 | package Unblock::HTTP1::Transaction; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 30 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 30 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 30 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 30 | ▶ | use Scalar::Util qw(weaken blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 30 | ▶ | use Uniform::HTTP::Response; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 30 | our $VERSION = '0.11'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 127 | ▶ | sub _new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=4 SCAR=14.9
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 127 | 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 | 127 | ▶ | 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 | 127 | weaken($self->{owner}); | |||||||||||||||||||||||||||||||||||||||||
| 26 | 127 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 195 | ▶ | sub request { $_[0]{request} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 82 | ▶ | sub response { $_[0]{response} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 24 | ▶ | sub state { $_[0]{state} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
state: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | sub error { $_[0]{error} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 39 | ▶ | sub is_complete { $_[0]{state} eq 'complete' ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_complete: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | sub is_cancelled { $_[0]{state} eq 'cancelled' ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_cancelled: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | sub is_error { $_[0]{state} eq 'error' ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_error: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 202 | ▶ | sub is_terminal { $_[0]{state} ne 'active' ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_terminal: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 11 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 11 | my ($self, $bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 11 | ▶ | croak 'write(): Transaction is terminal' if $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 10 | ▶ | my $owner = $self->{owner} or croak 'write(): HTTP/1 connection is gone'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 10 | return $owner->_transaction_write($self, $bytes, 0); | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | ▶ | sub end { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end: called CC=4 SCAR=14.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 7 | my ($self, $bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 7 | ▶ | croak 'end(): Transaction is terminal' if $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 7 | ▶ | my $owner = $self->{owner} or croak 'end(): HTTP/1 connection is gone'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 7 | ▶ | return $owner->_transaction_write($self, defined($bytes) ? $bytes : '', 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 56 | ▶ | sub respond { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
respond: called CC=12 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 56 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 56 | ▶ | croak 'respond(): Transaction is terminal' if $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 56 | ▶ | my $owner = $self->{owner} or croak 'respond(): HTTP/1 connection is gone'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 56 | my ($response, %option); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 56 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 41 | $response = shift @arg; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 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")
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | unless blessed($response) && $response->can('status') | ||||||||||||||||||||||||||||||||||||||||||
| 62 | && $response->can('header_count'); | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 40 | ▶ | croak 'respond(): options must be key/value pairs' if @arg % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 40 | %option = @arg; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 15 | ▶ | croak 'respond(): response fields must be key/value pairs' if @arg % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 15 | my %field = @arg; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 15 | for my $name (qw(stream_body on_drain)) { | |||||||||||||||||||||||||||||||||||||||||
| 69 | 30 | ▶ | $option{$name} = delete $field{$name} if exists $field{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 15 | $response = Uniform::HTTP::Response->new(%field); | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 55 | return $owner->_transaction_respond($self, $response, %option); | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 5 | ▶ | sub send_informational { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_informational: called CC=10 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 5 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 5 | ▶ | croak 'send_informational(): Transaction is terminal' if $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 5 | ▶ | my $owner = $self->{owner} or croak 'send_informational(): HTTP/1 connection is gone'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | my $response; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 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]
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | croak 'send_informational(): response object does not take options' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | unless @arg == 1; | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | $response = $arg[0]; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 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")
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | unless blessed($response) && $response->can('status') | ||||||||||||||||||||||||||||||||||||||||||
| 89 | && $response->can('header_count'); | ||||||||||||||||||||||||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | croak 'send_informational(): response fields must be key/value pairs' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | if @arg % 2; | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | $response = Uniform::HTTP::Response->new(@arg); | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | return $owner->_transaction_informational($self, $response); | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | ▶ | sub cancel { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cancel: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | ▶ | return $self if $self->is_terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | my $owner = $self->{owner}; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 4 | ▶ | $owner->_transaction_cancel($self) if $owner; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 100 | ▶ | sub _set_response { $_[0]{response} = $_[1]; return $_[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_response: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 58 | ▶ | sub _mark_local_done { $_[0]{local_done} = 1; return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mark_local_done: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 90 | ▶ | sub _mark_remote_done { $_[0]{remote_done} = 1; return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mark_remote_done: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 89 | ▶ | sub _mark_complete { $_[0]{state} = 'complete'; return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mark_complete: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | ▶ | sub _mark_cancelled { $_[0]{state} = 'cancelled'; return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mark_cancelled: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 29 | ▶ | sub _fail { $_[0]{state} = 'error'; $_[0]{error} = $_[1]; return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fail: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 149 | ▶ | sub _invoke { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_invoke: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 149 | my ($self, $name, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 149 | ▶ | my $cb = $self->{callbacks}{$name} or return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 100 | my $ok = eval { $cb->($self, @args); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 100 | ▶ | return $ok ? 1 : "$@"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 30 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||||||||||||||||