HTTP2/Client/Connection/AnyEvent.pm

filter: Statementstmt 84.6% 33 / 39 Branchbran 25.0% 1 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 10 / 12 Podpod n/a totaltotal 75.0% 45 / 60 SCAR 14.4
CC
4
Cov
76%
__ANON__
6.0
_start_io_if_needed
4.0
__ANON__
2.0
CRAP 4.2
« HTTP2/IOSocketSSL.pm ↑ Summary HTTP2/RejectorRegistry.pm »
1 package Net::HTTP2::Client::Connection::AnyEvent;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =encoding utf-8
7  
8 =head1 NAME
9  
10 Net::HTTP2::Client::Connection::AnyEvent
11  
12 =head1 SYNOPSIS
13  
14 my $cv = AnyEvent->condvar();
15  
16 my $h2 = Net::HTTP2::Client::Connection::AnyEvent->new("perl.org");
17  
18 $h2->request("GET", "/")->then(
19 sub ($resp) {
20 print $resp->content();
21 },
22 )->finally($cv);
23  
24 $cv->recv();
25  
26 =head1 DESCRIPTION
27  
28 This class extends L<Net::HTTP2::Client::Connection> to work with L<AnyEvent>.
29  
30 It requires that L<Net::SSLeay> support ALPN.
31  
32 =cut
33  
34 #----------------------------------------------------------------------
35  
36 1 ▶use parent 'Net::HTTP2::Client::Connection';
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 1 ▶use AnyEvent::TLS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use AnyEvent::Handle ();
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use Net::SSLeay ();
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 # perl -I ../p5-X-Tiny/lib -MData::Dumper -MAnyEvent -I ../p5-IO-SigGuard/lib -I ../p5-Promise-ES6/lib -Ilib -MNet::HTTP2::Client::Connection::AnyEvent -e'my $h2 = Net::HTTP2::Client::Connection::AnyEvent->new("google.com"); my $cv = AnyEvent->condvar(); $h2->request("GET", "/")->then( sub { print Dumper shift } )->finally($cv); $cv->recv();'
44  
45 sub _start_io_if_needed {
46 2 ▶ my ($self, $host, $port, $h2) = @_;
Subroutine _start_io_if_needed: called CC=3 SCAR=13.8
47  
48 2 ▶ $self->{'ae_handle'} ||= do {
Condition33%1/3
$self->{"ae_handle"} ||= do { my @tls_opts; if ($self->{"tls_verify_yn"}) { push @tls_opts, ("verify", 1, "verify_peername", "https"); } ; my $tls = "AnyEvent::TLS"->new(@tls_opts); &Net::SSLeay::CTX_set_alpn_protos(scalar $tls->ctx, scalar $self->_ALPN_PROTOS); my $weak_self = $self; builtin::weaken($weak_self); "AnyEvent::Handle"->new("connect", [$host, $port], "tls", "connect", "tls_ctx", $tls, "on_error", sub { my($handle, $fatal, $msg) = @_; $weak_self->_on_stream_error($msg); $handle->destroy; } , "on_eof", sub { $weak_self->_on_stream_close if $weak_self; (shift())->destroy; } , "on_read", sub { $h2->feed(substr($_[0]->rbuf, 0, length $_[0]->rbuf, "")); } ) }
l!l&&r!l&&!r
020
MC/DC0%0/2
$self->{"ae_handle"} ||= do { my @tls_opts; if ($self->{"tls_verify_yn"}) { push @tls_opts, ("verify", 1, "verify_peername", "https"); } ; my $tls = "AnyEvent::TLS"->new(@tls_opts); &Net::SSLeay::CTX_set_alpn_protos(scalar $tls->ctx, scalar $self->_ALPN_PROTOS); my $weak_self = $self; builtin::weaken($weak_self); "AnyEvent::Handle"->new("connect", [$host, $port], "tls", "connect", "tls_ctx", $tls, "on_error", sub { my($handle, $fatal, $msg) = @_; $weak_self->_on_stream_error($msg); $handle->destroy; } , "on_eof", sub { $weak_self->_on_stream_close if $weak_self; (shift())->destroy; } , "on_read", sub { $h2->feed(substr($_[0]->rbuf, 0, length $_[0]->rbuf, "")); } ) }
$self->{"ae_handle"} do { my @tls_opts; if ($self->{"tls_verify_yn"}) { push @tls_opts, ("verify", 1, "verify_peername", "https"); } ; my $tls = "AnyEvent::TLS"->new(@tls_opts); &Net::SSLeay::CTX_set_alpn_protos(scalar $tls->ctx, scalar $self->_ALPN_PROTOS); my $weak_self = $self; builtin::weaken($weak_self); "AnyEvent::Handle"->new("connect", [$host, $port], "tls", "connect", "tls_ctx", $tls, "on_error", sub { my($handle, $fatal, $msg) = @_; $weak_self->_on_stream_error($msg); $handle->destroy; } , "on_eof", sub { $weak_self->_on_stream_close if $weak_self; (shift())->destroy; } , "on_read", sub { $h2->feed(substr($_[0]->rbuf, 0, length $_[0]->rbuf, "")); } ) }
Truth table33%1/3
A ||= B
A= $self->{"ae_handle"}B= do { my @tls_opts; if ($self->{"tls_verify_yn"}) { push @tls_opts, ("verify", 1, "verify_peername", "https"); } ; my $tls = "AnyEvent::TLS"->new(@tls_opts); &Net::SSLeay::CTX_set_alpn_protos(scalar $tls->ctx, scalar $self->_ALPN_PROTOS); my $weak_self = $self; builtin::weaken($weak_self); "AnyEvent::Handle"->new("connect", [$host, $port], "tls", "connect", "tls_ctx", $tls, "on_error", sub { my($handle, $fatal, $msg) = @_; $weak_self->_on_stream_error($msg); $handle->destroy; } , "on_eof", sub { $weak_self->_on_stream_close if $weak_self; (shift())->destroy; } , "on_read", sub { $h2->feed(substr($_[0]->rbuf, 0, length $_[0]->rbuf, "")); } ) }
ABresult
1X1
011
000
49 2 my @tls_opts;
50  
51 2 ▶ if ($self->{'tls_verify_yn'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tls_verify_yn"}) 0 2 2
52 0 push @tls_opts, (
53 verify => 1,
54 verify_peername => 'https',
55 );
56 }
57  
58 2 my $tls = AnyEvent::TLS->new(@tls_opts);
59  
60 2 Net::SSLeay::CTX_set_alpn_protos($tls->ctx(), $self->_ALPN_PROTOS());
61  
62 2 my $weak_self = $self;
63 2 Scalar::Util::weaken($weak_self);
64  
65 AnyEvent::Handle->new(
66 connect => [$host, $port],
67 tls => 'connect',
68 tls_ctx => $tls,
69  
70 on_error => sub {
71 0 ▶ my ($handle, $fatal, $msg) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 0 $weak_self->_on_stream_error($msg);
73 0 $handle->destroy();
74 },
75  
76 on_eof => sub {
77 0 ▶ $weak_self->_on_stream_close() if $weak_self;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $weak_self 0 0 0
78 0 shift()->destroy();
79 },
80  
81 on_read => sub {
82 59 ▶ $h2->feed(
Subroutine __ANON__: called CC=1 SCAR=0.0
83 substr($_[0]->rbuf, 0, length $_[0]->rbuf, q<>),
84 );
85 },
86 2 );
87 };
88 }
89  
90 sub _write_frame {
91 14 ▶ $_[0]{'ae_handle'}->push_write($_[1]);
Subroutine _write_frame: called CC=1 SCAR=0.0
92 }
93  
94 1 1;
« HTTP2/IOSocketSSL.pm ↑ Summary HTTP2/RejectorRegistry.pm »