blib/lib/Unblock/HTTP1/Transaction.pm

filter: Statementstmt 100% 87 / 87 Branchbran 71.4% 40 / 56 Conditioncond 65.0% 13 / 20 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 100% 26 / 26 Podpod 100% 13 / 13 totaltotal 85.9% 183 / 213 CC 37 SCAR 17.6
CC
37
Cov
86%
respond
12.9
send_informational
11.0
_new
4.4
CRAP 5.8
« blib/lib/Unblock/HTTP1/_Engine.pm ↑ Summary blib/lib/Unblock/HTTP1/NativeABI.pm »
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
BranchTrueFalseTotal
$args{'local_done'} ? : 0 127 127
$args{'remote_done'} ? : 0 127 127
Condition50%1/2
$args{'callbacks'} || {}
l!l
1270
MC/DC0%0/1
$args{'callbacks'} || {}
$args{'callbacks'}
Truth table50%1/2
A
A= $args{'callbacks'}
Aresult
11
00
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
BranchTrueFalseTotal
$_[0]{'state'} eq 'complete' ? : 36 3 39
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
BranchTrueFalseTotal
$_[0]{'state'} eq 'cancelled' ? : 2 2 4
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
BranchTrueFalseTotal
$_[0]{'state'} eq 'error' ? : 1 2 3
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
BranchTrueFalseTotal
$_[0]{'state'} ne 'active' ? : 3 199 202
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
BranchTrueFalseTotal
if $self->is_terminal 1 10 11
41 10 ▶ my $owner = $self->{owner} or croak 'write(): HTTP/1 connection is gone';
Branch: 1 branch
BranchTrueFalseTotal
my $owner = $self->{"owner"} or croak("write(): HTTP/1 connection is gone") 10 0 10
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
BranchTrueFalseTotal
if $self->is_terminal 0 7 7
48 7 ▶ my $owner = $self->{owner} or croak 'end(): HTTP/1 connection is gone';
Branch: 1 branch
BranchTrueFalseTotal
my $owner = $self->{"owner"} or croak("end(): HTTP/1 connection is gone") 7 0 7
49 7 ▶ return $owner->_transaction_write($self, defined($bytes) ? $bytes : '', 1);
Branch: 1 branch
BranchTrueFalseTotal
defined $bytes ? : 7 0 7
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
BranchTrueFalseTotal
if $self->is_terminal 0 56 56
55 56 ▶ my $owner = $self->{owner} or croak 'respond(): HTTP/1 connection is gone';
Branch: 1 branch
BranchTrueFalseTotal
my $owner = $self->{"owner"} or croak("respond(): HTTP/1 connection is gone") 56 0 56
56  
57 56 my ($response, %option);
58 56 ▶ if (@arg && ref($arg[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg and ref $arg[0]) { } 41 15 56
Condition66%2/3
@arg and ref $arg[0]
!ll&&!rl&&r
01541
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]
ABresult
0X0
100
111
59 41 $response = shift @arg;
60 41 ▶ croak 'respond(): requires a Uniform HTTP response object'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($response) and $response->can("status") and $response->can("header_count") 1 40 41
Condition66%4/6
builtin::blessed($response) and $response->can("status") and $response->can("header_count")
!ll&&!rl&&r
1040
builtin::blessed($response) and $response->can("status")
!ll&&!rl&&r
1040
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")
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if @arg % 2 0 40 40
64 40 %option = @arg;
65 } else {
66 15 ▶ croak 'respond(): response fields must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 15 15
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
BranchTrueFalseTotal
if exists $field{$name} 2 28 30
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
BranchTrueFalseTotal
if $self->is_terminal 0 5 5
80 5 ▶ my $owner = $self->{owner} or croak 'send_informational(): HTTP/1 connection is gone';
Branch: 1 branch
BranchTrueFalseTotal
my $owner = $self->{"owner"} or croak("send_informational(): HTTP/1 connection is gone") 5 0 5
81  
82 5 my $response;
83 5 ▶ if (@arg && ref($arg[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg and ref $arg[0]) { } 3 2 5
Condition66%2/3
@arg and ref $arg[0]
!ll&&!rl&&r
023
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]
ABresult
0X0
100
111
84 3 ▶ croak 'send_informational(): response object does not take options'
Branch: 1 branch
BranchTrueFalseTotal
unless @arg == 1 0 3 3
85 unless @arg == 1;
86 3 $response = $arg[0];
87 3 ▶ croak 'send_informational(): requires a Uniform HTTP response object'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($response) and $response->can("status") and $response->can("header_count") 1 2 3
Condition66%4/6
builtin::blessed($response) and $response->can("status") and $response->can("header_count")
!ll&&!rl&&r
102
builtin::blessed($response) and $response->can("status")
!ll&&!rl&&r
102
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")
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if @arg % 2 0 2 2
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
BranchTrueFalseTotal
if $self->is_terminal 0 4 4
102 4 my $owner = $self->{owner};
103 4 ▶ $owner->_transaction_cancel($self) if $owner;
Branch: 1 branch
BranchTrueFalseTotal
if $owner 4 0 4
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
BranchTrueFalseTotal
my $cb = $self->{"callbacks"}{$name} or return 1 100 49 149
117 100 my $ok = eval { $cb->($self, @args); 1 };
118 100 ▶ return $ok ? 1 : "$@";
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 99 1 100
119 }
120  
121 30 1;
122  
123 __END__
« blib/lib/Unblock/HTTP1/_Engine.pm ↑ Summary blib/lib/Unblock/HTTP1/NativeABI.pm »