blib/lib/EV/Websockets.pm

filter: Statementstmt 94.1% 32 / 34 Branchbran 57.1% 8 / 14 Conditioncond 50.0% 11 / 22 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 67.4% 60 / 89 SCAR 31.3
CC
17
Cov
73%
new
28.4
_parse_proxy
5.0
BEGIN
1.0
CRAP 22.8
↑ Summary Websockets.xs »
1 package EV::Websockets;
2 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 20 ▶use EV;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 BEGIN {
8 20 ▶ use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 ▶ our $VERSION = '0.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 20 XSLoader::load __PACKAGE__, $VERSION;
11 }
12  
13 package EV::Websockets::Context;
14  
15 # Parse a proxy value (typically from *_proxy env vars) into ($host, $port).
16 # Accepts an optional scheme prefix and userinfo, plain host:port, and IPv6
17 # bracket notation. Returns an empty list if no host can be extracted; the
18 # port defaults to 1080 when the value carries a host but no explicit port.
19 sub _parse_proxy {
20 37 ▶ my ($url) = @_;
Subroutine _parse_proxy: called CC=5 SCAR=16.1
21 37 ▶ return unless defined $url && length $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url and length $url 26 11 37
Condition100%3/3
defined $url and length $url
!ll&&!rl&&r
25111
MC/DC100%2/2
defined $url and length $url
defined $url length $url
Truth table100%3/3
A and B
A= defined $urlB= length $url
ABresult
0X0
100
111
22 11 ▶ return unless $url =~ m{^(?:\w+://)?(?:[^@]+\@)?(\[[\w:]+\]|[^:/]+)(?::(\d+))?};
Branch: 1 branch
BranchTrueFalseTotal
unless $url =~ m(^(?:\w+://)?(?:[^\@]+\@)?(\[[\w:]+\]|[^:/]+)(?::(\d+))?) 0 11 11
23 # Capture before the substitution below: a successful s/// resets $2.
24 11 my ($host, $port) = ($1, $2);
25 # Strip IPv6 brackets: lws wants a bare proxy host (the port is passed
26 # separately), matching how connect() unwraps bracketed URL hosts.
27 11 $host =~ s/^\[(.*)\]\z/$1/;
28 11 ▶ return ($host, defined $port ? $port : 1080);
Branch: 1 branch
BranchTrueFalseTotal
defined $port ? : 7 4 11
29 }
30  
31 sub new {
32 24 ▶ my ($class, %args) = @_;
Subroutine new: called CC=13 SCAR=33.5
33 24 ▶ my $loop = $args{loop} // EV::default_loop;
Condition33%1/3
$args{"loop"} // &EV::default_loop()
l!l&&r!l&&!r
0240
MC/DC0%0/2
$args{"loop"} // &EV::default_loop()
$args{"loop"} &EV::default_loop()
Truth table33%1/3
A // B
A= $args{"loop"}B= &EV::default_loop()
ABresult
1X1
011
000
34  
35 24 my $proxy = $args{proxy};
36 24 my $proxy_port = $args{proxy_port};
37  
38 24 ▶ if (!defined $proxy) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $proxy) 24 0 24
39 24 ▶ my $env_proxy = $ENV{https_proxy} // $ENV{http_proxy} // $ENV{all_proxy};
Condition33%2/6
($ENV{"https_proxy"} // $ENV{"http_proxy"}) // $ENV{"all_proxy"}
l!l&&r!l&&!r
0024
$ENV{"https_proxy"} // $ENV{"http_proxy"}
l!l&&r!l&&!r
0024
MC/DC0%0/3
($ENV{"https_proxy"} // $ENV{"http_proxy"}) // $ENV{"all_proxy"}
$ENV{"https_proxy"} $ENV{"http_proxy"} $ENV{"all_proxy"}
Truth table25%1/4
A // B // C
A= $ENV{"https_proxy"}B= $ENV{"http_proxy"}C= $ENV{"all_proxy"}
ABCresult
1XX1
01X1
0011
0000
40 24 my ($host, $port) = _parse_proxy($env_proxy);
41 24 ▶ if (defined $host) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $host) 0 24 24
42 0 $proxy = $host;
43 0 $proxy_port = $port;
44 }
45 }
46  
47 24 ▶ $proxy //= "";
Condition50%1/2
$proxy //= ""
l!l
024
MC/DC0%0/1
$proxy //= ""
$proxy
Truth table50%1/2
A
A= $proxy
Aresult
11
00
48 24 ▶ $proxy_port //= 0;
Condition50%1/2
$proxy_port //= 0
l!l
024
MC/DC0%0/1
$proxy_port //= 0
$proxy_port
Truth table50%1/2
A
A= $proxy_port
Aresult
11
00
49  
50 return $class->_new($loop, $proxy, $proxy_port,
51 $args{ssl_cert} // "", $args{ssl_key} // "", $args{ssl_ca} // "",
52 24 ▶ exists $args{ssl_init} ? ($args{ssl_init} ? 1 : 0) : -1);
Branch: 2 branches
BranchTrueFalseTotal
exists $args{'ssl_init'} ? : 0 24 24
$args{'ssl_init'} ? : 0 0 0
Condition50%3/6
$args{"ssl_cert"} // ""
l!l
024
$args{"ssl_key"} // ""
l!l
024
$args{"ssl_ca"} // ""
l!l
024
MC/DC0%0/1
$args{"ssl_cert"} // ""
$args{"ssl_cert"}
MC/DC0%0/1
$args{"ssl_key"} // ""
$args{"ssl_key"}
MC/DC0%0/1
$args{"ssl_ca"} // ""
$args{"ssl_ca"}
Truth table50%1/2
A
A= $args{"ssl_cert"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"ssl_key"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"ssl_ca"}
Aresult
11
00
53 }
54  
55 package EV::Websockets::Connection;
56  
57 20 1;
58  
59 __END__
↑ Summary Websockets.xs »