blib/lib/Langertha/Holmgang/Sim/Linux/Http.pm

filter: Statementstmt 80.7% 290 / 359 Branchbran 62.9% 156 / 248 Conditioncond 43.4% 135 / 311 MC/DCmcdc 17.6% 30 / 170 Subroutinesub 91.6% 22 / 24 Podpod 100% 10 / 10 totaltotal 57.3% 643 / 1122 CC 260 SCAR 60.8
CC
260
Cov
63%
curl
986.4
request
184.6
respond
49.4
CRAP 435.8
« blib/lib/Langertha/Holmgang/Sim/Linux/Docker.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Storage.pm »
1 package Langertha::Holmgang::Sim::Linux::Http;
2 # ABSTRACT: HTTP between simulated devices: curl, applications behind ports, probes at the end state
3  
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 our $VERSION = '0.001';
11  
12  
13 5 my $JSON = JSON::MaybeXS->new( utf8 => 0, canonical => 1, allow_nonref => 1 );
14  
15 5 our %REASON = (
16 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 204 => 'No Content', 301 => 'Moved Permanently',
17 302 => 'Found', 304 => 'Not Modified', 307 => 'Temporary Redirect', 308 => 'Permanent Redirect',
18 400 => 'Bad Request', 401 => 'Unauthorized', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Not Allowed',
19 408 => 'Request Time-out', 413 => 'Request Entity Too Large', 421 => 'Misdirected Request',
20 426 => 'Upgrade Required', 429 => 'Too Many Requests', 494 => 'Request Header Or Cookie Too Large',
21 495 => 'SSL Certificate Error', 496 => 'No Required SSL Certificate', 500 => 'Internal Server Error',
22 502 => 'Bad Gateway', 503 => 'Service Temporarily Unavailable', 504 => 'Gateway Time-out',
23 );
24  
25 250 ▶sub _linux { require Langertha::Holmgang::Sim::Linux; return 'Langertha::Holmgang::Sim::Linux' }
Subroutine _linux: called CC=1 SCAR=0.0
26  
27 546 ▶sub _nginx_on { my ($d) = @_; return ref $d eq 'HASH' && ref $d->{nginx} eq 'HASH' }
Subroutine _nginx_on: called CC=2 SCAR=7.1
Condition66%2/3
ref $d eq 'HASH' && ref $$d{'nginx'} eq 'HASH'
!ll&&!rl&&r
0244302
MC/DC50%1/2
ref $d eq 'HASH' && ref $$d{'nginx'} eq 'HASH'
ref $d eq 'HASH' ref $$d{'nginx'} eq 'HASH'
Truth table66%2/3
A && B
A= ref $d eq 'HASH'B= ref $$d{'nginx'} eq 'HASH'
ABresult
0X0
100
111
28 427 ▶sub _docker_on { my ($d) = @_; return ref $d eq 'HASH' && ref $d->{docker} eq 'HASH' }
Subroutine _docker_on: called CC=2 SCAR=7.1
Condition66%2/3
ref $d eq 'HASH' && ref $$d{'docker'} eq 'HASH'
!ll&&!rl&&r
034780
MC/DC50%1/2
ref $d eq 'HASH' && ref $$d{'docker'} eq 'HASH'
ref $d eq 'HASH' ref $$d{'docker'} eq 'HASH'
Truth table66%2/3
A && B
A= ref $d eq 'HASH'B= ref $$d{'docker'} eq 'HASH'
ABresult
0X0
100
111
29  
30  
31 179 ▶sub before {
Subroutine before: called CC=5 SCAR=16.1
Pod documented
32 179 my ($state) = @_;
33 179 ▶ return unless ref $state eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $state eq "HASH" 0 179 179
34 179 for my $h ( sort keys %$state ) {
35 343 my $d = $state->{$h};
36 343 ▶ if ( _nginx_on($d) ) { require Langertha::Holmgang::Sim::Linux::Nginx; Langertha::Holmgang::Sim::Linux::Nginx::ensure( $d, $h, $state ) }
Branch: 1 branch
BranchTrueFalseTotal
if (_nginx_on($d)) 100 243 343
37 343 ▶ if ( _docker_on($d) ) { Langertha::Holmgang::Sim::Linux::_part('Docker'); Langertha::Holmgang::Sim::Linux::Docker::ensure( $d, $h, $state ) }
Branch: 1 branch
BranchTrueFalseTotal
if (_docker_on($d)) 79 264 343
38 }
39 179 return;
40 }
41  
42 179 ▶sub after {
Subroutine after: called CC=21 SCAR=32.2
Pod documented
43 179 my ($state) = @_;
44 179 ▶ return unless ref $state eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $state eq "HASH" 0 179 179
45 179 for my $h ( sort keys %$state ) {
46 343 my $d = $state->{$h};
47 343 ▶ next unless ref $d eq 'HASH' && ref $d->{probes} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $d eq "HASH" and ref $$d{"probes"} eq "HASH" 243 100 343
Condition66%2/3
ref $d eq "HASH" and ref $$d{"probes"} eq "HASH"
!ll&&!rl&&r
0243100
MC/DC50%1/2
ref $d eq "HASH" and ref $$d{"probes"} eq "HASH"
ref $d eq "HASH" ref $$d{"probes"} eq "HASH"
Truth table66%2/3
A and B
A= ref $d eq "HASH"B= ref $$d{"probes"} eq "HASH"
ABresult
0X0
100
111
48 100 for my $n ( sort keys %{ $d->{probes} } ) {
49 100 my $p = $d->{probes}{$n};
50 100 ▶ next unless ref $p eq 'HASH' && defined $p->{url};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $p eq "HASH" and defined $$p{"url"} 0 100 100
Condition33%1/3
ref $p eq "HASH" and defined $$p{"url"}
!ll&&!rl&&r
00100
MC/DC0%0/2
ref $p eq "HASH" and defined $$p{"url"}
ref $p eq "HASH" defined $$p{"url"}
Truth table33%1/3
A and B
A= ref $p eq "HASH"B= defined $$p{"url"}
ABresult
0X0
100
111
51 my $res = request( $state, $h, {
52 url => $p->{url},
53 method => $p->{method} // 'GET',
54 0 ▶ headers => { map { lc($_) => $p->{headers}{$_} } keys %{ $p->{headers} || {} } },
Condition50%1/2
$$p{'headers'} || {}
l!l
0100
MC/DC0%0/1
$$p{'headers'} || {}
$$p{'headers'}
Truth table50%1/2
A
A= $$p{'headers'}
Aresult
11
00
55 100 ▶ map { exists $p->{$_} ? ( $_ => $p->{$_} ) : () } qw( insecure resolve cacert cert key body_size max_time follow tls_version sni ),
Branch: 1 branch
BranchTrueFalseTotal
exists $$p{$_} ? : 0 1000 1000
Condition50%1/2
$$p{"method"} // "GET"
l!l
0100
MC/DC0%0/1
$$p{"method"} // "GET"
$$p{"method"}
Truth table50%1/2
A
A= $$p{"method"}
Aresult
11
00
56 } );
57 100 ▶ my %r = ( status => $res->{status} // 0 );
Condition100%2/2
$$res{"status"} // 0
l!l
6733
MC/DC100%1/1
$$res{"status"} // 0
$$res{"status"}
Truth table100%2/2
A
A= $$res{"status"}
Aresult
11
00
58 100 ▶ $r{error} = $res->{error} if defined $res->{error};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$res{"error"} 33 67 100
59 100 ▶ for my $k (qw( body cert protocol )) { $r{$k} = $res->{$k} if defined $res->{$k} }
Branch: 1 branch
BranchTrueFalseTotal
if defined $$res{$k} 77 223 300
60 100 ▶ $r{headers} = { map { lc( $_->[0] ) => $_->[1] } @{ $res->{headers} || [] } } if $res->{headers};
Branch: 1 branch
BranchTrueFalseTotal
if $$res{"headers"} 67 33 100
Condition50%1/2
$$res{'headers'} || []
l!l
670
MC/DC0%0/1
$$res{'headers'} || []
$$res{'headers'}
Truth table50%1/2
A
A= $$res{'headers'}
Aresult
11
00
61 100 ▶ $r{location} = $r{headers}{location} if $r{headers} && defined $r{headers}{location};
Branch: 1 branch
BranchTrueFalseTotal
if $r{"headers"} and defined $r{"headers"}{"location"} 0 100 100
Condition66%2/3
$r{"headers"} and defined $r{"headers"}{"location"}
!ll&&!rl&&r
33670
MC/DC0%0/2
$r{"headers"} and defined $r{"headers"}{"location"}
$r{"headers"} defined $r{"headers"}{"location"}
Truth table66%2/3
A and B
A= $r{"headers"}B= defined $r{"headers"}{"location"}
ABresult
0X0
100
111
62 100 ▶ $r{backend} = $res->{backend} if $res->{backend};
Branch: 1 branch
BranchTrueFalseTotal
if $$res{"backend"} 61 39 100
63 100 ▶ $r{redirects} = $res->{redirects} if $res->{redirects};
Branch: 1 branch
BranchTrueFalseTotal
if $$res{"redirects"} 0 100 100
64 100 $p->{result} = \%r;
65 }
66 }
67 179 return;
68 }
69  
70 # --- Adressen ---------------------------------------------------------------------
71  
72  
73 # Adressen eines Geraets (ohne Laenge)
74 459 ▶sub addresses {
Subroutine addresses: called CC=4 SCAR=14.0
Pod documented
75 459 my ($d) = @_;
76 459 my @a = ('127.0.0.1');
77 459 ▶ for my $if ( values %{ $d->{interfaces} || {} } ) { push @a, map { s{/.*}{}r } @{ $if->{addr} || [] } }
Condition50%2/4
$$d{'interfaces'} || {}
l!l
4590
$$if{'addr'} || []
l!l
5430
MC/DC0%0/1
$$d{'interfaces'} || {}
$$d{'interfaces'}
MC/DC0%0/1
$$if{'addr'} || []
$$if{'addr'}
Truth table50%1/2
A
A= $$d{'interfaces'}
Aresult
11
00
Truth table50%1/2
A
A= $$if{'addr'}
Aresult
11
00
78 459 return @a;
79 }
80  
81  
82 # Name -> ( geraet, ip ) vom fragenden Geraet aus; () wenn unbekannt
83 203 ▶sub resolve {
Subroutine resolve: called CC=15 SCAR=38.8
Pod documented
84 203 my ( $state, $from, $name, $override ) = @_;
85 203 my $d = $state->{$from};
86 203 my $ip;
87 203 ▶ if ( $name =~ /\A\d+\.\d+\.\d+\.\d+\z/ ) { $ip = $name }
Branch: 3 branches
BranchTrueFalseTotal
if ($name =~ /\A\d+\.\d+\.\d+\.\d+\z/) { } 79 124 203
elsif (defined $override) { } 0 124 124
elsif ($name eq 'localhost') { } 0 124 124
88 0 elsif ( defined $override ) { $ip = $override }
89 0 elsif ( $name eq 'localhost' ) { $ip = '127.0.0.1' }
90 else {
91 124 ▶ ($ip) = _linux()->can('_resolve')->( $d, $name ) if ref $d eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $d eq "HASH" 124 0 124
92 124 ▶ if ( !defined $ip ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ip) 0 124 124
93 # Rueckfall: der Name eines Geraets im Zustand (bzw. sein hostname)
94 0 ▶ my ($h) = grep { $_ eq $name || ( ref $state->{$_} eq 'HASH' && ( $state->{$_}{hostname} // '' ) eq $name ) } sort keys %$state;
Condition0%0/8
$_ eq $name || ref $$state{$_} eq 'HASH' && ($$state{$_}{'hostname'} // '') eq $name
l!l&&r!l&&!r
000
ref $$state{$_} eq "HASH" and ($$state{$_}{"hostname"} // "") eq $name
!ll&&!rl&&r
000
$$state{$_}{"hostname"} // ""
l!l
00
MC/DC0%0/3
$_ eq $name || ref $$state{$_} eq 'HASH' && ($$state{$_}{'hostname'} // '') eq $name
$_ eq $name ref $$state{$_} eq "HASH" $$state{$_}{"hostname"}
Truth table0%0/4
A || B and C
A= $_ eq $nameB= ref $$state{$_} eq "HASH"C= $$state{$_}{"hostname"}
ABCresult
1XX1
0111
00X0
0100
95 0 ▶ return () unless defined $h;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h 0 0 0
96 0 my @a = grep { $_ ne '127.0.0.1' } addresses( $state->{$h} );
97 0 ▶ return ( $h, $a[0] // '127.0.0.1' );
Condition0%0/2
$a[0] // "127.0.0.1"
l!l
00
MC/DC0%0/1
$a[0] // "127.0.0.1"
$a[0]
Truth table0%0/2
A
A= $a[0]
Aresult
11
00
98 }
99 }
100 203 ▶ return ( $from, $ip ) if $ip =~ /\A127\./;
Branch: 1 branch
BranchTrueFalseTotal
if $ip =~ /\A127\./ 78 125 203
101 125 for my $h ( sort keys %$state ) {
102 334 ▶ next unless ref $state->{$h} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$state{$h} eq "HASH" 0 334 334
103 334 ▶ return ( $h, $ip ) if grep { $_ eq $ip } addresses( $state->{$h} );
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $ip;} addresses($$state{$h}) 125 209 334
104 }
105 0 return ( undef, $ip );
106 }
107  
108 # --- Anfrage --------------------------------------------------------------------
109  
110  
111  
112 230 ▶sub parse_url {
Subroutine parse_url: called CC=6 SCAR=18.3
Pod documented
113 230 my ($u) = @_;
114 230 ▶ $u = "http://$u" unless $u =~ m{\A[a-z]+://}i;
Branch: 1 branch
BranchTrueFalseTotal
unless $u =~ m[\A[a-z]+://]i 0 230 230
115 230 ▶ my ( $scheme, $host, $port, $path ) = $u =~ m{\A([a-z]+)://(\[[^\]]+\]|[^/:?#]+)(?::(\d+))?([^#]*)}i or return;
Branch: 1 branch
BranchTrueFalseTotal
() = $u =~ m(\A([a-z]+)://(\[[^\]]+\]|[^/:?#]+)(?::(\d+))?([^#]*))i or return 230 0 230
116 230 $scheme = lc $scheme;
117 230 ▶ $path = '/' . $path if $path !~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ m[\A/] 0 230 230
118 230 ▶ return { scheme => $scheme, host => lc $host, port => $port // ( $scheme eq 'https' ? 443 : 80 ), path => $path };
Branch: 1 branch
BranchTrueFalseTotal
$scheme eq 'https' ? : 44 104 148
Condition100%2/2
$port // ($scheme eq "https" ? 443 : 80)
l!l
82148
MC/DC100%1/1
$port // ($scheme eq "https" ? 443 : 80)
$port
Truth table100%2/2
A
A= $port
Aresult
11
00
119 }
120  
121 203 ▶sub request {
Subroutine request: called CC=44 SCAR=52.2
Pod documented
122 203 my ( $state, $from, $req, $depth ) = @_;
123 203 ▶ $depth //= 0;
Condition100%2/2
$depth //= 0
l!l
76127
MC/DC100%1/1
$depth //= 0
$depth
Truth table100%2/2
A
A= $depth
Aresult
11
00
124 203 ▶ my $u = parse_url( $req->{url} // '' ) or return { error => "(3) URL using bad/illegal format or missing URL", code => 3 };
Branch: 1 branch
BranchTrueFalseTotal
my $u = parse_url($$req{"url"} // "") or return {"error", "(3) URL using bad/illegal format or missing URL", "code", 3} 203 0 203
Condition50%1/2
$$req{"url"} // ""
l!l
2030
MC/DC0%0/1
$$req{"url"} // ""
$$req{"url"}
Truth table50%1/2
A
A= $$req{"url"}
Aresult
11
00
125 203 ▶ return { error => "(1) Protocol \"$u->{scheme}\" not supported", code => 1 } unless $u->{scheme} =~ /\Ahttps?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $$u{"scheme"} =~ /\Ahttps?\z/ 0 203 203
126 203 my %r = ( %$req, %$u );
127 203 ▶ $r{method} = uc( $r{method} // 'GET' );
Condition50%1/2
$r{"method"} // "GET"
l!l
2030
MC/DC0%0/1
$r{"method"} // "GET"
$r{"method"}
Truth table50%1/2
A
A= $r{"method"}
Aresult
11
00
128 203 ▶ $r{headers} = { %{ $req->{headers} || {} } };
Condition50%1/2
$$req{'headers'} || {}
l!l
2030
MC/DC0%0/1
$$req{'headers'} || {}
$$req{'headers'}
Truth table50%1/2
A
A= $$req{'headers'}
Aresult
11
00
129 203 ▶ $r{headers}{host} //= $u->{host} . ( $u->{port} == ( $u->{scheme} eq 'https' ? 443 : 80 ) ? '' : ":$u->{port}" );
Branch: 2 branches
BranchTrueFalseTotal
$$u{'port'} == ($$u{'scheme'} eq 'https' ? 443 : 80) ? : 100 0 100
$$u{'scheme'} eq 'https' ? : 36 64 100
Condition100%2/2
$r{"headers"}{"host"} //= $$u{"host"} . ($$u{"port"} == ($$u{"scheme"} eq "https" ? 443 : 80) ? "" : qq[:$$u{"port"}])
l!l
103100
MC/DC100%1/1
$r{"headers"}{"host"} //= $$u{"host"} . ($$u{"port"} == ($$u{"scheme"} eq "https" ? 443 : 80) ? "" : qq[:$$u{"port"}])
$r{"headers"}{"host"}
Truth table100%2/2
A
A= $r{"headers"}{"host"}
Aresult
11
00
130 203 my $override;
131 203 ▶ for my $rv ( ref $req->{resolve} ? @{ $req->{resolve} } : grep {defined} $req->{resolve} ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $$req{'resolve'} ? : 26 177 203
132 0 my ( $n, $p, $ip ) = split /:/, $rv, 3;
133 0 ▶ $override = $ip if defined $ip && lc($n) eq $u->{host} && $p == $u->{port};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ip and lc $n eq $$u{"host"} and $p == $$u{"port"} 0 0 0
Condition0%0/6
defined $ip and lc $n eq $$u{"host"} and $p == $$u{"port"}
!ll&&!rl&&r
000
defined $ip and lc $n eq $$u{"host"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $ip and lc $n eq $$u{"host"} and $p == $$u{"port"}
defined $ip lc $n eq $$u{"host"} $p == $$u{"port"}
Truth table0%0/4
A and B and C
A= defined $ipB= lc $n eq $$u{"host"}C= $p == $$u{"port"}
ABCresult
0XX0
10X0
1100
1111
134 }
135 203 my ( $to, $ip ) = resolve( $state, $from, $u->{host}, $override );
136 203 ▶ return { error => "(6) Could not resolve host: $u->{host}", code => 6 } unless defined $ip;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip 0 203 203
137 203 $r{ip} = $ip;
138 203 ▶ $r{client_ip} //= $to && $to eq $from ? '127.0.0.1' : _source_ip( $state->{$from}, $ip );
Branch: 1 branch
BranchTrueFalseTotal
$to && $to eq $from ? : 78 125 203
Condition50%3/6
$r{"client_ip"} //= $to && $to eq $from ? "127.0.0.1" : _source_ip($$state{$from}, $ip)
l!l&&r!l&&!r
02030
$to and $to eq $from
!ll&&!rl&&r
012578
MC/DC0%0/3
$r{"client_ip"} //= $to && $to eq $from ? "127.0.0.1" : _source_ip($$state{$from}, $ip)
$r{"client_ip"} $to $to eq $from
Truth table0%0/4
A //= B and C
A= $r{"client_ip"}B= $toC= $to eq $from
ABCresult
1XX1
0111
00X0
0100
139 203 my $refused = { error => "(7) Failed to connect to $u->{host} port $u->{port} after 0 ms: Couldn't connect to server", code => 7 };
140 203 ▶ return $refused unless defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to 0 203 203
141 203 my $dev = $state->{$to};
142 203 my $res;
143 203 ▶ if ( _nginx_on($dev) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_nginx_on($dev)) 202 1 203
144 202 require Langertha::Holmgang::Sim::Linux::Nginx;
145 202 $res = Langertha::Holmgang::Sim::Linux::Nginx::serve( $state, $to, \%r, $from, $depth );
146 }
147 203 ▶ if ( !$res && _docker_on($dev) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $res and _docker_on($dev)) 1 202 203
Condition100%3/3
not $res and _docker_on($dev)
!ll&&!rl&&r
119831
MC/DC100%2/2
not $res and _docker_on($dev)
not $res _docker_on($dev)
Truth table100%3/3
not(A) and B
A= not $resB= _docker_on($dev)
ABresult
0X0
100
111
148 1 Langertha::Holmgang::Sim::Linux::_part('Docker');
149 1 $res = Langertha::Holmgang::Sim::Linux::Docker::serve( $state, $to, \%r, $from, $depth );
150 }
151 203 ▶ $res //= app_serve( $state, $to, \%r, $from );
Condition100%3/3
$res //= app_serve($state, $to, \%r, $from)
l!l&&r!l&&!r
1207310
MC/DC100%2/2
$res //= app_serve($state, $to, \%r, $from)
$res app_serve($state, $to, \%r, $from)
Truth table100%3/3
A //= B
A= $resB= app_serve($state, $to, \%r, $from)
ABresult
1X1
011
000
152 203 ▶ return $refused unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 10 193 203
153 193 ▶ return $res if defined $res->{error};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$res{"error"} 2 191 193
154 # TLS: der Client prueft, was der Server vorzeigt
155 191 ▶ if ( $u->{scheme} eq 'https' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$u{"scheme"} eq "https") 37 154 191
156 37 ▶ if ( !$res->{tls} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$res{"tls"}) 1 36 37
157 1 return { error => '(35) OpenSSL/3.0.15: error:0A00010B:SSL routines::wrong version number', code => 35 };
158 }
159 36 ▶ if ( !$req->{insecure} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$req{"insecure"}) 34 2 36
160 34 require Langertha::Holmgang::Sim::Linux::Pki;
161 34 ▶ if ( my $bad = Langertha::Holmgang::Sim::Linux::Pki::client_verify( $state, $from, $res->{tls}, \%r ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $bad = Langertha::Holmgang::Sim::Linux::Pki::client_verify($state, $from, $$res{"tls"}, \%r)) 28 6 34
162 28 return { error => $bad->[1], code => $bad->[0], tls_lines => $res->{tls}{lines} };
163 }
164 }
165 }
166 162 my $max = $req->{max_time};
167 162 ▶ if ( defined $max && ( $res->{delay} // 0 ) > $max ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and ($$res{"delay"} // 0) > $max) 0 162 162
Condition20%1/5
defined $max and ($$res{"delay"} // 0) > $max
!ll&&!rl&&r
16200
$$res{"delay"} // 0
l!l
00
MC/DC0%0/2
defined $max and ($$res{"delay"} // 0) > $max
defined $max $$res{"delay"}
Truth table33%1/3
A and B
A= defined $maxB= $$res{"delay"}
ABresult
0X0
100
111
168 0 return { error => sprintf( '(28) Operation timed out after %d milliseconds with 0 bytes received', $max * 1000 + 1 ), code => 28 };
169 }
170 162 ▶ if ( $req->{follow} && ( $res->{status} // 0 ) =~ /\A30[1278]\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$req{"follow"} and ($$res{"status"} // 0) =~ /\A30[1278]\z/) 0 162 162
Condition20%1/5
$$req{"follow"} and ($$res{"status"} // 0) =~ /\A30[1278]\z/
!ll&&!rl&&r
16200
$$res{"status"} // 0
l!l
00
MC/DC0%0/2
$$req{"follow"} and ($$res{"status"} // 0) =~ /\A30[1278]\z/
$$req{"follow"} $$res{"status"}
Truth table33%1/3
A and B
A= $$req{"follow"}B= $$res{"status"}
ABresult
0X0
100
111
171 0 ▶ my ($loc) = map { $_->[1] } grep { lc( $_->[0] ) eq 'location' } @{ $res->{headers} || [] };
Condition0%0/2
$$res{'headers'} || []
l!l
00
MC/DC0%0/1
$$res{'headers'} || []
$$res{'headers'}
Truth table0%0/2
A
A= $$res{'headers'}
Aresult
11
00
172 0 ▶ if ( defined $loc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $loc) 0 0 0
173 0 ▶ my $n = ( $req->{_redirects} // 0 ) + 1;
Condition0%0/2
$$req{"_redirects"} // 0
l!l
00
MC/DC0%0/1
$$req{"_redirects"} // 0
$$req{"_redirects"}
Truth table0%0/2
A
A= $$req{"_redirects"}
Aresult
11
00
174 0 ▶ return { error => "(47) Maximum (50) redirects followed", code => 47, redirects => $n - 1 } if $n > 50;
Branch: 1 branch
BranchTrueFalseTotal
if $n > 50 0 0 0
175 0 ▶ my $next = $loc =~ m{\A[a-z]+://}i ? $loc : "$u->{scheme}://$u->{host}" . ( $loc =~ m{\A/} ? $loc : "/$loc" );
Branch: 2 branches
BranchTrueFalseTotal
$loc =~ m[\A[a-z]+://]i ? : 0 0 0
$loc =~ m[\A/] ? : 0 0 0
176 0 ▶ my %h = %{ $req->{headers} || {} };
Condition0%0/2
$$req{'headers'} || {}
l!l
00
MC/DC0%0/1
$$req{'headers'} || {}
$$req{'headers'}
Truth table0%0/2
A
A= $$req{'headers'}
Aresult
11
00
177 0 delete $h{host};
178 0 my $r2 = request( $state, $from, { %$req, url => $next, headers => \%h, _redirects => $n }, $depth );
179 0 ▶ $r2->{redirects} //= $n;
Condition0%0/3
$$r2{"redirects"} //= $n
l!l&&r!l&&!r
000
MC/DC0%0/2
$$r2{"redirects"} //= $n
$$r2{"redirects"} $n
Truth table0%0/3
A //= B
A= $$r2{"redirects"}B= $n
ABresult
1X1
011
000
180 0 return $r2;
181 }
182 }
183 162 return $res;
184 }
185  
186 125 ▶sub _source_ip {
Subroutine _source_ip: called CC=8 SCAR=21.3
187 125 my ( $d, $to ) = @_;
188 125 my @a = grep { $_ ne '127.0.0.1' } addresses($d);
189 125 ▶ for my $if ( values %{ $d->{interfaces} || {} } ) {
Condition50%1/2
$$d{'interfaces'} || {}
l!l
1250
MC/DC0%0/1
$$d{'interfaces'} || {}
$$d{'interfaces'}
Truth table50%1/2
A
A= $$d{'interfaces'}
Aresult
11
00
190 125 ▶ for my $c ( @{ $if->{addr} || [] } ) {
Condition50%1/2
$$if{'addr'} || []
l!l
1250
MC/DC0%0/1
$$if{'addr'} || []
$$if{'addr'}
Truth table50%1/2
A
A= $$if{'addr'}
Aresult
11
00
191 125 my ( $ip, $len ) = split m{/}, $c;
192 125 ▶ return $ip if defined $len && _linux()->can('_in')->( $to, "$ip/$len" );
Branch: 1 branch
BranchTrueFalseTotal
if defined $len and _linux()->can("_in")->($to, "$ip/$len") 124 1 125
Condition66%2/3
defined $len and _linux()->can("_in")->($to, "$ip/$len")
!ll&&!rl&&r
01124
MC/DC50%1/2
defined $len and _linux()->can("_in")->($to, "$ip/$len")
defined $len _linux()->can("_in")->($to, "$ip/$len")
Truth table66%2/3
A and B
A= defined $lenB= _linux()->can("_in")->($to, "$ip/$len")
ABresult
0X0
100
111
193 }
194 }
195 1 ▶ return $a[0] // '127.0.0.1';
Condition50%1/2
$a[0] // "127.0.0.1"
l!l
10
MC/DC0%0/1
$a[0] // "127.0.0.1"
$a[0]
Truth table50%1/2
A
A= $a[0]
Aresult
11
00
196 }
197  
198 # --- Anwendungen (http) -----------------------------------------------------------
199  
200  
201 # Passt ein Lauscher "ip:port" | "port" auf ( ip, port )? 127.* nur vom Geraet selbst.
202 78 ▶sub listens {
Subroutine listens: called CC=12 SCAR=31.9
Pod documented
203 78 my ( $key, $ip, $port, $local ) = @_;
204 78 ▶ my ( $lip, $lport ) = $key =~ /\A(?:(.+):)?(\d+)\z/ or return 0;
Branch: 1 branch
BranchTrueFalseTotal
() = $key =~ /\A(?:(.+):)?(\d+)\z/ or return 0 78 0 78
205 78 ▶ return 0 unless $lport == $port;
Branch: 1 branch
BranchTrueFalseTotal
unless $lport == $port 4 74 78
206 74 ▶ $lip //= '0.0.0.0';
Condition50%1/2
$lip //= "0.0.0.0"
l!l
740
MC/DC0%0/1
$lip //= "0.0.0.0"
$lip
Truth table50%1/2
A
A= $lip
Aresult
11
00
207 74 ▶ $lip = '0.0.0.0' if $lip eq '*' || $lip eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $lip eq "*" or $lip eq "" 0 74 74
Condition33%1/3
$lip eq "*" or $lip eq ""
l!l&&r!l&&!r
0074
MC/DC0%0/2
$lip eq "*" or $lip eq ""
$lip eq "*" $lip eq ""
Truth table33%1/3
A or B
A= $lip eq "*"B= $lip eq ""
ABresult
1X1
011
000
208 74 ▶ return 1 if $lip eq '0.0.0.0';
Branch: 1 branch
BranchTrueFalseTotal
if $lip eq "0.0.0.0" 0 74 74
209 74 ▶ return 0 if $lip =~ /\A127\./ && !$local;
Branch: 1 branch
BranchTrueFalseTotal
if $lip =~ /\A127\./ and not $local 0 74 74
Condition33%1/3
$lip =~ /\A127\./ and not $local
!ll&&!rl&&r
0740
MC/DC0%0/2
$lip =~ /\A127\./ and not $local
$lip =~ /\A127\./ not $local
Truth table33%1/3
A and not(B)
A= $lip =~ /\A127\./B= not $local
ABresult
0X0
100
111
210 74 ▶ return $lip eq $ip || ( $lip =~ /\A127\./ && $ip =~ /\A127\./ ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$lip eq $ip || $lip =~ /\A127\./ && $ip =~ /\A127\./ ? : 74 0 74
Condition16%1/6
$lip eq $ip or $lip =~ /\A127\./ and $ip =~ /\A127\./
l!l&&r!l&&!r
7400
$lip =~ /\A127\./ and $ip =~ /\A127\./
!ll&&!rl&&r
000
MC/DC0%0/3
$lip eq $ip or $lip =~ /\A127\./ and $ip =~ /\A127\./
$lip eq $ip $lip =~ /\A127\./ $ip =~ /\A127\./
Truth table25%1/4
A or B and C
A= $lip eq $ipB= $lip =~ /\A127\./C= $ip =~ /\A127\./
ABCresult
1XX1
0111
00X0
0100
211 }
212  
213  
214 83 ▶sub app_serve {
Subroutine app_serve: called CC=8 SCAR=21.1
Pod documented
215 83 my ( $state, $to, $req, $from ) = @_;
216 83 my $dev = $state->{$to};
217 83 ▶ my $apps = ref $dev->{http} eq 'HASH' ? $dev->{http} : return undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'http'} eq 'HASH' ? : 78 5 83
218 78 ▶ my $local = defined $from && $from eq $to;
Condition66%2/3
defined $from && $from eq $to
!ll&&!rl&&r
0276
MC/DC50%1/2
defined $from && $from eq $to
defined $from $from eq $to
Truth table66%2/3
A && B
A= defined $fromB= $from eq $to
ABresult
0X0
100
111
219 78 ▶ my ($key) = grep { listens( $_, $req->{ip}, $req->{port}, $local ) } sort keys %$apps or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my($key) = grep({listens($_, $$req{"ip"}, $$req{"port"}, $local);} sort(keys %$apps)) or return undef 74 4 78
220 74 my $app = $apps->{$key};
221 74 ▶ if ( defined $app->{service} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$app{"service"}) 74 0 74
222 74 ▶ my $svc = ( $dev->{services} || {} )->{ $app->{service} };
Condition50%1/2
$$dev{'services'} || {}
l!l
740
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
223 74 ▶ return undef unless $svc && $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $svc and $$svc{"active"} 1 73 74
Condition66%2/3
$svc and $$svc{"active"}
!ll&&!rl&&r
0173
MC/DC50%1/2
$svc and $$svc{"active"}
$svc $$svc{"active"}
Truth table66%2/3
A and B
A= $svcB= $$svc{"active"}
ABresult
0X0
100
111
224 }
225 73 return respond( $app, $req, "$to $key" );
226 }
227  
228  
229 75 ▶sub respond {
Subroutine respond: called CC=18 SCAR=39.0
Pod documented
230 75 my ( $app, $req, $name ) = @_;
231 75 ▶ my $path = $req->{path} // '/';
Condition50%1/2
$$req{"path"} // "/"
l!l
750
MC/DC0%0/1
$$req{"path"} // "/"
$$req{"path"}
Truth table50%1/2
A
A= $$req{"path"}
Aresult
11
00
232 75 ( my $bare = $path ) =~ s/\?.*//;
233 75 ▶ my %h = %{ $req->{headers} || {} };
Condition50%1/2
$$req{'headers'} || {}
l!l
750
MC/DC0%0/1
$$req{'headers'} || {}
$$req{'headers'}
Truth table50%1/2
A
A= $$req{'headers'}
Aresult
11
00
234 2 ▶ my $fill = sub {
Subroutine __ANON__: called CC=5 SCAR=18.7
235 2 my ($t) = @_;
236 2 ▶ return $t unless defined $t && !ref $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t and not ref $t 0 2 2
Condition33%1/3
defined $t and not ref $t
!ll&&!rl&&r
002
MC/DC0%0/2
defined $t and not ref $t
defined $t not ref $t
Truth table33%1/3
A and not(B)
A= defined $tB= not ref $t
ABresult
0X0
100
111
237 2 ▶ my $host = $h{host} // '';
Condition50%1/2
$h{"host"} // ""
l!l
20
MC/DC0%0/1
$h{"host"} // ""
$h{"host"}
Truth table50%1/2
A
A= $h{"host"}
Aresult
11
00
238 2 $host =~ s/:\d+\z//;
239 2 $t =~ s/\{host\}/$host/g;
240 2 $t =~ s/\{path\}/$path/g;
241 0 ▶ $t =~ s/\{header:([\w-]+)\}/$h{lc $1} \/\/ ''/ge;
Condition0%0/2
$h{lc $1} // ""
l!l
00
MC/DC0%0/1
$h{lc $1} // ""
$h{lc $1}
Truth table0%0/2
A
A= $h{lc $1}
Aresult
11
00
242 2 return $t;
243 75 };
244 my $backend = { app => $name, path => $path, host => $h{host},
245 75 ▶ headers => { map { $_ => $h{$_} } grep { $_ ne 'host' && $_ ne 'user-agent' && $_ ne 'accept' } sort keys %h } };
Condition100%6/6
$_ ne 'host' && $_ ne 'user-agent' && $_ ne 'accept'
!ll&&!rl&&r
881378
$_ ne "host" and $_ ne "user-agent"
!ll&&!rl&&r
751391
MC/DC100%3/3
$_ ne 'host' && $_ ne 'user-agent' && $_ ne 'accept'
$_ ne "host" $_ ne "user-agent" $_ ne 'accept'
Truth table100%4/4
A and B && C
A= $_ ne "host"B= $_ ne "user-agent"C= $_ ne 'accept'
ABCresult
0XX0
10X0
1100
1111
246 75 ▶ my $mk = sub {
Subroutine __ANON__: called CC=7 SCAR=20.7
247 75 my ($s) = @_;
248 0 ▶ my @hd = map { [ $_, $fill->( $s->{headers}{$_} ) ] } sort keys %{ $s->{headers} || {} };
Condition50%1/2
$$s{'headers'} || {}
l!l
075
MC/DC0%0/1
$$s{'headers'} || {}
$$s{'headers'}
Truth table50%1/2
A
A= $$s{'headers'}
Aresult
11
00
249 my $body = $s->{echo}
250 ? $JSON->encode( { method => $req->{method}, path => $path, headers => { %h } } ) . "\n"
251 75 ▶ : $fill->( $s->{body} // '' );
Branch: 1 branch
BranchTrueFalseTotal
$$s{'echo'} ? : 73 2 75
Condition50%1/2
$$s{"body"} // ""
l!l
20
MC/DC0%0/1
$$s{"body"} // ""
$$s{"body"}
Truth table50%1/2
A
A= $$s{"body"}
Aresult
11
00
252 return { status => $s->{status} // 200, headers => \@hd, body => $body, backend => $backend,
253 75 ▶ delay => $s->{delay} // $app->{delay} // 0 };
Condition71%5/7
$$s{"status"} // 200
l!l
075
($$s{"delay"} // $$app{"delay"}) // 0
l!l
273
$$s{"delay"} // $$app{"delay"}
l!l&&r!l&&!r
2073
MC/DC0%0/1
$$s{"status"} // 200
$$s{"status"}
MC/DC50%1/2
($$s{"delay"} // $$app{"delay"}) // 0
$$s{"delay"} $$app{"delay"}
Truth table50%1/2
A
A= $$s{"status"}
Aresult
11
00
Truth table66%2/3
A // B
A= $$s{"delay"}B= $$app{"delay"}
ABresult
1X1
011
000
254 75 };
255 75 ▶ for my $c ( @{ $app->{require} || [] } ) {
Condition50%1/2
$$app{'require'} || []
l!l
075
MC/DC0%0/1
$$app{'require'} || []
$$app{'require'}
Truth table50%1/2
A
A= $$app{'require'}
Aresult
11
00
256 0 ▶ my $v = $h{ lc( $c->{header} // '' ) };
Condition0%0/2
$$c{"header"} // ""
l!l
00
MC/DC0%0/1
$$c{"header"} // ""
$$c{"header"}
Truth table0%0/2
A
A= $$c{"header"}
Aresult
11
00
257 0 my $ok = defined $v;
258 0 ▶ $ok &&= $v eq $c->{equals} if $ok && defined $c->{equals};
Branch: 1 branch
BranchTrueFalseTotal
if $ok and defined $$c{"equals"} 0 0 0
Condition0%0/6
$ok and defined $$c{"equals"}
!ll&&!rl&&r
000
$ok &&= $v eq $$c{"equals"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ok and defined $$c{"equals"}
$ok defined $$c{"equals"}
MC/DC0%0/2
$ok &&= $v eq $$c{"equals"}
$ok $v eq $$c{"equals"}
Truth table0%0/3
A and B
A= $okB= defined $$c{"equals"}
ABresult
0X0
100
111
Truth table0%0/3
A &&= B
A= $okB= $v eq $$c{"equals"}
ABresult
0X0
100
111
259 0 ▶ $ok &&= $v =~ /$c->{regex}/ if $ok && defined $c->{regex};
Branch: 1 branch
BranchTrueFalseTotal
if $ok and defined $$c{"regex"} 0 0 0
Condition0%0/6
$ok and defined $$c{"regex"}
!ll&&!rl&&r
000
$ok &&= $v =~ /$$c{"regex"}/
!ll&&!rl&&r
000
MC/DC0%0/2
$ok and defined $$c{"regex"}
$ok defined $$c{"regex"}
MC/DC0%0/2
$ok &&= $v =~ /$$c{"regex"}/
$ok $v =~ /$$c{"regex"}/
Truth table0%0/3
A and B
A= $okB= defined $$c{"regex"}
ABresult
0X0
100
111
Truth table0%0/3
A &&= B
A= $okB= $v =~ /$$c{"regex"}/
ABresult
0X0
100
111
260 0 ▶ $ok = !defined $v if exists $c->{absent};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$c{"absent"} 0 0 0
261 0 ▶ return $mk->($c) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
262 }
263 4 my ($route) = sort { length $b->{path} <=> length $a->{path} }
264 75 ▶ grep { substr( $bare, 0, length $_->{path} ) eq $_->{path} } @{ $app->{routes} || [ { path => '/' } ] };
Condition50%1/2
$$app{'routes'} || [{'path', '/'}]
l!l
750
MC/DC0%0/1
$$app{'routes'} || [{'path', '/'}]
$$app{'routes'}
Truth table50%1/2
A
A= $$app{'routes'}
Aresult
11
00
265 75 ▶ return $mk->( $route || { status => 404, body => "Not Found\n" } );
Condition50%1/2
$route || {'status', 404, 'body', "Not Found\n"}
l!l
750
MC/DC0%0/1
$route || {'status', 404, 'body', "Not Found\n"}
$route
Truth table50%1/2
A
A= $route
Aresult
11
00
266 }
267  
268 # --- curl ---------------------------------------------------------------------------
269  
270  
271 5 my %CURL_FLAG = map { $_ => 1 } qw( -s --silent -S --show-error -f --fail --fail-with-body -k --insecure -I --head
272 -i --include -v --verbose -L --location -4 -6 --http1.1 --http1.0 --http2 --compressed -N --no-buffer -g --globoff
273 --no-progress-meter -q --ipv4 --ipv6 --tlsv1.2 --tlsv1.3 --ssl-no-revoke );
274 5 my %CURL_ARG = map { $_ => 1 } qw( -o --output -w --write-out -H --header -X --request -d --data --data-binary
275 --data-raw --data-urlencode -F --form --resolve --cacert --capath --cert --key -m --max-time --connect-timeout
276 -u --user -A --user-agent -e --referer -b --cookie -c --cookie-jar --max-redirs -T --upload-file --interface
277 --retry --retry-delay --cert-type --key-type --pass --url --tls-max --ciphers );
278  
279 26 ▶sub curl {
Subroutine curl: called CC=114 SCAR=68.9
Pod documented
280 26 my ( $dev, $av, $ctx ) = @_;
281 26 ▶ my $state = $ctx->{state} || { $ctx->{host} => $dev };
Condition50%1/2
$$ctx{'state'} || {$$ctx{'host'}, $dev}
l!l
260
MC/DC0%0/1
$$ctx{'state'} || {$$ctx{'host'}, $dev}
$$ctx{'state'}
Truth table50%1/2
A
A= $$ctx{'state'}
Aresult
11
00
282 26 my $from = $ctx->{host};
283 26 my ( %f, @hdr, @res, $url, $out_file, $wfmt, $method, $body );
284 26 my @a = @$av;
285 26 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 71 26 97
286 71 my $x = shift @a;
287 71 ▶ if ( $x =~ /\A-([a-zA-Z]{2,})\z/ ) { # -sSfL, -sSo datei
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /\A-([a-zA-Z]{2,})\z/) 7 64 71
288 7 my @c = split //, $1;
289 7 ▶ my $takes = $CURL_ARG{"-$c[-1]"} ? pop @c : undef;
Branch: 1 branch
BranchTrueFalseTotal
$CURL_ARG{"-$c[-1]"} ? : 0 7 7
290 return ( "curl: option $x: is unknown\ncurl: try 'curl --help' or 'curl --manual' for more information", 0 )
291 7 ▶ if grep { !$CURL_FLAG{"-$_"} } @c;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $CURL_FLAG{"-$_"};} @c 0 7 7
292 7 $f{"-$_"} = 1 for @c;
293 7 ▶ unshift @a, "-$takes" if defined $takes;
Branch: 1 branch
BranchTrueFalseTotal
if defined $takes 0 7 7
294 7 next;
295 }
296 0 ▶ if ( $x =~ /\A(--[\w.-]+)=(.*)\z/s && $CURL_ARG{$1} ) { unshift @a, $1, $2; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /\A(--[\w.-]+)=(.*)\z/s and $CURL_ARG{$1}) 0 64 64
Condition33%1/3
$x =~ /\A(--[\w.-]+)=(.*)\z/s and $CURL_ARG{$1}
!ll&&!rl&&r
6400
MC/DC0%0/2
$x =~ /\A(--[\w.-]+)=(.*)\z/s and $CURL_ARG{$1}
$x =~ /\A(--[\w.-]+)=(.*)\z/s $CURL_ARG{$1}
Truth table33%1/3
A and B
A= $x =~ /\A(--[\w.-]+)=(.*)\z/sB= $CURL_ARG{$1}
ABresult
0X0
100
111
297 64 ▶ if ( $CURL_FLAG{$x} ) { $f{$x} = 1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($CURL_FLAG{$x}) 19 45 64
298 45 ▶ if ( $CURL_ARG{$x} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CURL_ARG{$x}) 19 26 45
299 19 my $v = shift @a;
300 19 ▶ return ( "curl: option $x: requires parameter\ncurl: try 'curl --help' or 'curl --manual' for more information", 0 ) unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 19 19
301 19 ▶ if ( $x eq '-o' || $x eq '--output' ) { $out_file = $v }
Branch: 10 branches
BranchTrueFalseTotal
if ($x eq '-o' or $x eq '--output') { } 6 13 19
elsif ($x eq '-w' or $x eq '--write-out') { } 6 7 13
elsif ($x eq '-H' or $x eq '--header') { } 5 2 7
elsif ($x eq '-X' or $x eq '--request') { } 0 2 2
elsif ($x =~ /\A(?:-d|--data(?:-binary|-raw|-urlencode)?|-F|--form|-T|--upload-file)\z/) { } 1 1 2
elsif ($x eq '--resolve') { } 0 1 1
elsif ($x eq '-m' or $x eq '--max-time') { } 0 1 1
elsif ($x eq '-u' or $x eq '--user') { } 0 1 1
elsif ($x eq '-A' or $x eq '--user-agent') { } 0 1 1
elsif ($x eq '--url') { } 0 1 1
Condition66%2/3
$x eq "-o" or $x eq "--output"
l!l&&r!l&&!r
6013
MC/DC50%1/2
$x eq "-o" or $x eq "--output"
$x eq "-o" $x eq "--output"
Truth table66%2/3
A or B
A= $x eq "-o"B= $x eq "--output"
ABresult
1X1
011
000
302 6 ▶ elsif ( $x eq '-w' || $x eq '--write-out' ) { $wfmt = $v }
Condition66%2/3
$x eq "-w" or $x eq "--write-out"
l!l&&r!l&&!r
607
MC/DC50%1/2
$x eq "-w" or $x eq "--write-out"
$x eq "-w" $x eq "--write-out"
Truth table66%2/3
A or B
A= $x eq "-w"B= $x eq "--write-out"
ABresult
1X1
011
000
303 5 ▶ elsif ( $x eq '-H' || $x eq '--header' ) { push @hdr, $v }
Condition66%2/3
$x eq "-H" or $x eq "--header"
l!l&&r!l&&!r
502
MC/DC50%1/2
$x eq "-H" or $x eq "--header"
$x eq "-H" $x eq "--header"
Truth table66%2/3
A or B
A= $x eq "-H"B= $x eq "--header"
ABresult
1X1
011
000
304 0 ▶ elsif ( $x eq '-X' || $x eq '--request' ) { $method = $v }
Condition33%1/3
$x eq "-X" or $x eq "--request"
l!l&&r!l&&!r
002
MC/DC0%0/2
$x eq "-X" or $x eq "--request"
$x eq "-X" $x eq "--request"
Truth table33%1/3
A or B
A= $x eq "-X"B= $x eq "--request"
ABresult
1X1
011
000
305 elsif ( $x =~ /\A(?:-d|--data(?:-binary|-raw|-urlencode)?|-F|--form|-T|--upload-file)\z/ ) {
306 1 my $len = length $v;
307 1 ▶ if ( $v =~ /\@(\S+)\z/ || $x eq '-T' || $x eq '--upload-file' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /\@(\S+)\z/ or $x eq "-T" or $x eq "--upload-file") 1 0 1
Condition33%2/6
$v =~ /\@(\S+)\z/ or $x eq "-T" or $x eq "--upload-file"
l!l&&r!l&&!r
100
$v =~ /\@(\S+)\z/ or $x eq "-T"
l!l&&r!l&&!r
100
MC/DC0%0/3
$v =~ /\@(\S+)\z/ or $x eq "-T" or $x eq "--upload-file"
$v =~ /\@(\S+)\z/ $x eq "-T" $x eq "--upload-file"
Truth table25%1/4
A or B or C
A= $v =~ /\@(\S+)\z/B= $x eq "-T"C= $x eq "--upload-file"
ABCresult
1XX1
01X1
0011
0000
308 1 ▶ my $p = $x =~ /\A(?:-T|--upload-file)\z/ ? $v : $1;
Branch: 1 branch
BranchTrueFalseTotal
$x =~ /\A(?:-T|--upload-file)\z/ ? : 0 1 1
309 1 my $L = _linux();
310 1 ▶ my $e = $L->can('_file_entry')->( $dev, $p ) or return ( "curl: (26) Failed to open/read local data from file/application", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $e = $L->can("_file_entry")->($dev, $p) or return "curl: (26) Failed to open/read local data from file/application", 0 1 0 1
311 1 $len = $L->can('_file_size')->($e);
312 }
313 1 ▶ $body = ( $body // 0 ) + $len;
Condition50%1/2
$body // 0
l!l
01
MC/DC0%0/1
$body // 0
$body
Truth table50%1/2
A
A= $body
Aresult
11
00
314 1 ▶ $method //= $x =~ /\A(?:-T|--upload-file)\z/ ? 'PUT' : 'POST';
Branch: 1 branch
BranchTrueFalseTotal
$x =~ /\A(?:-T|--upload-file)\z/ ? : 0 1 1
Condition50%1/2
$method //= $x =~ /\A(?:-T|--upload-file)\z/ ? "PUT" : "POST"
l!l
01
MC/DC0%0/1
$method //= $x =~ /\A(?:-T|--upload-file)\z/ ? "PUT" : "POST"
$method
Truth table50%1/2
A
A= $method
Aresult
11
00
315 }
316 0 elsif ( $x eq '--resolve' ) { push @res, $v }
317 0 ▶ elsif ( $x eq '-m' || $x eq '--max-time' ) { $f{max_time} = $v }
Condition33%1/3
$x eq "-m" or $x eq "--max-time"
l!l&&r!l&&!r
001
MC/DC0%0/2
$x eq "-m" or $x eq "--max-time"
$x eq "-m" $x eq "--max-time"
Truth table33%1/3
A or B
A= $x eq "-m"B= $x eq "--max-time"
ABresult
1X1
011
000
318 0 ▶ elsif ( $x eq '-u' || $x eq '--user' ) { push @hdr, 'Authorization: Basic ' . _b64($v) }
Condition33%1/3
$x eq "-u" or $x eq "--user"
l!l&&r!l&&!r
001
MC/DC0%0/2
$x eq "-u" or $x eq "--user"
$x eq "-u" $x eq "--user"
Truth table33%1/3
A or B
A= $x eq "-u"B= $x eq "--user"
ABresult
1X1
011
000
319 0 ▶ elsif ( $x eq '-A' || $x eq '--user-agent' ) { push @hdr, "User-Agent: $v" }
Condition33%1/3
$x eq "-A" or $x eq "--user-agent"
l!l&&r!l&&!r
001
MC/DC0%0/2
$x eq "-A" or $x eq "--user-agent"
$x eq "-A" $x eq "--user-agent"
Truth table33%1/3
A or B
A= $x eq "-A"B= $x eq "--user-agent"
ABresult
1X1
011
000
320 0 elsif ( $x eq '--url' ) { $url = $v }
321 1 else { $f{$x} = $v }
322 19 next;
323 }
324 26 ▶ return ( "curl: option $x: is unknown\ncurl: try 'curl --help' or 'curl --manual' for more information", 0 ) if $x =~ /\A-/;
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /\A-/ 0 26 26
325 26 ▶ $url //= $x;
Condition33%1/3
$url //= $x
l!l&&r!l&&!r
0260
MC/DC0%0/2
$url //= $x
$url $x
Truth table33%1/3
A //= B
A= $urlB= $x
ABresult
1X1
011
000
326 }
327 26 ▶ return ( "curl: no URL specified!\ncurl: try 'curl --help' or 'curl --manual' for more information", 0 ) unless defined $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url 0 26 26
328 26 ▶ my $silent = $f{'-s'} || $f{'--silent'};
Condition33%1/3
$f{'-s'} || $f{'--silent'}
l!l&&r!l&&!r
2600
MC/DC0%0/2
$f{'-s'} || $f{'--silent'}
$f{'-s'} $f{'--silent'}
Truth table33%1/3
A || B
A= $f{'-s'}B= $f{'--silent'}
ABresult
1X1
011
000
329 26 ▶ my $show = $f{'-S'} || $f{'--show-error'};
Condition66%2/3
$f{'-S'} || $f{'--show-error'}
l!l&&r!l&&!r
4022
MC/DC50%1/2
$f{'-S'} || $f{'--show-error'}
$f{'-S'} $f{'--show-error'}
Truth table66%2/3
A || B
A= $f{'-S'}B= $f{'--show-error'}
ABresult
1X1
011
000
330 26 ▶ my $head = $f{'-I'} || $f{'--head'};
Condition66%2/3
$f{'-I'} || $f{'--head'}
l!l&&r!l&&!r
2024
MC/DC50%1/2
$f{'-I'} || $f{'--head'}
$f{'-I'} $f{'--head'}
Truth table66%2/3
A || B
A= $f{'-I'}B= $f{'--head'}
ABresult
1X1
011
000
331 26 my %h = ( 'user-agent' => 'curl/7.88.1', accept => '*/*' );
332 26 ▶ for (@hdr) { my ( $k, $v ) = /\A([^:]+):\s*(.*)\z/ or next; $h{ lc $k } = $v }
Branch: 1 branch
BranchTrueFalseTotal
() = /\A([^:]+):\s*(.*)\z/ or next 5 0 5
333 26 ▶ my $u = parse_url($url) // {};
Condition50%1/2
parse_url($url) // {}
l!l
260
MC/DC0%0/1
parse_url($url) // {}
parse_url($url)
Truth table50%1/2
A
A= parse_url($url)
Aresult
11
00
334 26 ▶ $h{host} //= $u->{host} . ( ( $u->{port} // 80 ) == ( ( $u->{scheme} // '' ) eq 'https' ? 443 : 80 ) ? '' : ":$u->{port}" ) if $u->{host};
Branch: 3 branches
BranchTrueFalseTotal
if $$u{"host"} 26 0 26
($$u{'port'} // 80) == (($$u{'scheme'} // '') eq 'https' ? 443 : 80) ? : 23 2 25
($$u{'scheme'} // '') eq 'https' ? : 5 20 25
Condition66%4/6
$h{"host"} //= $$u{"host"} . (($$u{"port"} // 80) == (($$u{"scheme"} // "") eq "https" ? 443 : 80) ? "" : qq[:$$u{"port"}])
l!l
125
$$u{"port"} // 80
l!l
250
$$u{"scheme"} // ""
l!l
250
MC/DC100%1/1
$h{"host"} //= $$u{"host"} . (($$u{"port"} // 80) == (($$u{"scheme"} // "") eq "https" ? 443 : 80) ? "" : qq[:$$u{"port"}])
$h{"host"}
MC/DC0%0/1
$$u{"port"} // 80
$$u{"port"}
MC/DC0%0/1
$$u{"scheme"} // ""
$$u{"scheme"}
Truth table100%2/2
A
A= $h{"host"}
Aresult
11
00
Truth table50%1/2
A
A= $$u{"port"}
Aresult
11
00
Truth table50%1/2
A
A= $$u{"scheme"}
Aresult
11
00
335 my $req = {
336 url => $url, method => $method // ( $head ? 'HEAD' : 'GET' ), headers => \%h,
337 resolve => \@res, insecure => $f{'-k'} || $f{'--insecure'}, follow => $f{'-L'} || $f{'--location'},
338 ( defined $body ? ( body_size => $body ) : () ),
339 26 ▶ map { defined $f{"--$_"} ? ( $_ => $f{"--$_"} ) : () } qw( cacert cert key ),
Branch: 3 branches
BranchTrueFalseTotal
$head ? : 2 23 25
defined $body ? : 1 25 26
defined $f{"--$_"} ? : 1 77 78
Condition62%5/8
$method // ($head ? "HEAD" : "GET")
l!l
125
$f{'-k'} || $f{'--insecure'}
l!l&&r!l&&!r
1025
$f{'-L'} || $f{'--location'}
l!l&&r!l&&!r
0026
MC/DC100%1/1
$method // ($head ? "HEAD" : "GET")
$method
MC/DC50%1/2
$f{'-k'} || $f{'--insecure'}
$f{'-k'} $f{'--insecure'}
MC/DC0%0/2
$f{'-L'} || $f{'--location'}
$f{'-L'} $f{'--location'}
Truth table100%2/2
A
A= $method
Aresult
11
00
Truth table66%2/3
A || B
A= $f{'-k'}B= $f{'--insecure'}
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $f{'-L'}B= $f{'--location'}
ABresult
1X1
011
000
340 };
341 26 ▶ $req->{max_time} = $f{max_time} if defined $f{max_time} && $f{max_time} =~ /\A\d+(?:\.\d+)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $f{"max_time"} and $f{"max_time"} =~ /\A\d+(?:\.\d+)?\z/ 0 26 26
Condition33%1/3
defined $f{"max_time"} and $f{"max_time"} =~ /\A\d+(?:\.\d+)?\z/
!ll&&!rl&&r
2600
MC/DC0%0/2
defined $f{"max_time"} and $f{"max_time"} =~ /\A\d+(?:\.\d+)?\z/
defined $f{"max_time"} $f{"max_time"} =~ /\A\d+(?:\.\d+)?\z/
Truth table33%1/3
A and B
A= defined $f{"max_time"}B= $f{"max_time"} =~ /\A\d+(?:\.\d+)?\z/
ABresult
0X0
100
111
342 26 my $res = request( $state, $from, $req );
343 26 my @v; # -v
344 26 ▶ my $verbose = $f{'-v'} || $f{'--verbose'};
Condition33%1/3
$f{'-v'} || $f{'--verbose'}
l!l&&r!l&&!r
0026
MC/DC0%0/2
$f{'-v'} || $f{'--verbose'}
$f{'-v'} $f{'--verbose'}
Truth table33%1/3
A || B
A= $f{'-v'}B= $f{'--verbose'}
ABresult
1X1
011
000
345 26 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 26 26
346 0 ▶ my ( undef, $ip ) = $u->{host} ? resolve( $state, $from, $u->{host} ) : ();
Branch: 1 branch
BranchTrueFalseTotal
$$u{'host'} ? : 0 0 0
347 0 ▶ if ( defined $ip ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ip) 0 0 0
348 0 push @v, "* Trying $ip:$u->{port}...";
349 0 ▶ push @v, "* Connected to $u->{host} ($ip) port $u->{port} (#0)" unless ( $res->{code} // 0 ) == 7;
Branch: 1 branch
BranchTrueFalseTotal
unless ($$res{"code"} // 0) == 7 0 0 0
Condition0%0/2
$$res{"code"} // 0
l!l
00
MC/DC0%0/1
$$res{"code"} // 0
$$res{"code"}
Truth table0%0/2
A
A= $$res{"code"}
Aresult
11
00
350 }
351 0 ▶ push @v, @{ $res->{tls_lines} || [] } if $u->{scheme} && $u->{scheme} eq 'https';
Branch: 1 branch
BranchTrueFalseTotal
if $$u{"scheme"} and $$u{"scheme"} eq "https" 0 0 0
Condition0%0/5
$$u{"scheme"} and $$u{"scheme"} eq "https"
!ll&&!rl&&r
000
$$res{'tls_lines'} || []
l!l
00
MC/DC0%0/2
$$u{"scheme"} and $$u{"scheme"} eq "https"
$$u{"scheme"} $$u{"scheme"} eq "https"
MC/DC0%0/1
$$res{'tls_lines'} || []
$$res{'tls_lines'}
Truth table0%0/3
A and B
A= $$u{"scheme"}B= $$u{"scheme"} eq "https"
ABresult
0X0
100
111
Truth table0%0/2
A
A= $$res{'tls_lines'}
Aresult
11
00
352 }
353 26 my $code = $res->{code};
354 0 ▶ if ( !defined $code && ( $f{'-f'} || $f{'--fail'} ) && ( $res->{status} // 0 ) >= 400 ) { $code = 22 }
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $code and $f{"-f"} || $f{"--fail"} and ($$res{"status"} // 0) >= 400) 0 26 26
Condition36%4/11
not defined $code and $f{"-f"} || $f{"--fail"} and ($$res{"status"} // 0) >= 400
!ll&&!rl&&r
2600
not defined $code and $f{"-f"} || $f{"--fail"}
!ll&&!rl&&r
5210
$f{"-f"} or $f{"--fail"}
l!l&&r!l&&!r
0021
$$res{"status"} // 0
l!l
00
MC/DC0%0/4
not defined $code and $f{"-f"} || $f{"--fail"} and ($$res{"status"} // 0) >= 400
not defined $code $f{"-f"} $f{"--fail"} $$res{"status"}
Truth table33%2/6
not(A) and B or C and D
A= not defined $codeB= $f{"-f"}C= $f{"--fail"}D= $$res{"status"}
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
355 26 my @out;
356 26 ▶ if ( defined $res->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$res{"error"}) 5 21 26
357 5 push @out, @v;
358 5 ▶ push @out, "* $res->{error}" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 5 5
359 5 ▶ push @out, "curl: $res->{error}" if !$silent || $show;
Branch: 1 branch
BranchTrueFalseTotal
if not $silent or $show 4 1 5
Condition66%2/3
not $silent or $show
l!l&&r!l&&!r
041
MC/DC50%1/2
not $silent or $show
not $silent $show
Truth table66%2/3
not(A) or B
A= not $silentB= $show
ABresult
1X1
011
000
360 push @out, 'More details here: https://curl.se/docs/sslcerts.html', '',
361 'curl failed to verify the legitimacy of the server and therefore could not',
362 'establish a secure connection to it. To learn more about this situation and',
363 'how to fix it, please visit the web page mentioned above.'
364 5 ▶ if ( $res->{code} // 0 ) == 60 && ( !$silent || $show );
Branch: 1 branch
BranchTrueFalseTotal
if ($$res{"code"} // 0) == 60 and !$silent || $show 2 3 5
Condition50%4/8
($$res{"code"} // 0) == 60 and !$silent || $show
!ll&&!rl&&r
302
$$res{"code"} // 0
l!l
50
not $silent or $show
l!l&&r!l&&!r
020
MC/DC0%0/3
($$res{"code"} // 0) == 60 and !$silent || $show
$$res{"code"} not $silent $show
Truth table25%1/4
A and not(B) or C
A= $$res{"code"}B= not $silentC= $show
ABCresult
0XX0
1000
11X1
1011
365 5 ▶ push @out, _wout( $wfmt, { http_code => '000' }, $url ) if defined $wfmt;
Branch: 1 branch
BranchTrueFalseTotal
if defined $wfmt 0 5 5
366 5 return ( join( "\n", @out ), 0 );
367 }
368 21 ▶ my $status = $res->{status} // 200;
Condition50%1/2
$$res{"status"} // 200
l!l
210
MC/DC0%0/1
$$res{"status"} // 200
$$res{"status"}
Truth table50%1/2
A
A= $$res{"status"}
Aresult
11
00
369 21 ▶ my @hl = ( "HTTP/1.1 $status " . ( $REASON{$status} // '' ), _resp_headers($res) );
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::Http::REASON{$status} // ""
l!l
210
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::Http::REASON{$status} // ""
$Langertha::Holmgang::Sim::Linux::Http::REASON{$status}
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::Http::REASON{$status}
Aresult
11
00
370 21 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 21 21
371 push @v, "> $req->{method} " . ( $u->{path} // '/' ) . ' HTTP/1.1', "> Host: " . ( $h{host} // '' ),
372 0 ( map { '> ' . _hname($_) . ": $h{$_}" } grep { exists $h{$_} } 'user-agent', 'accept',
373 0 ▶ grep { !/\A(?:host|user-agent|accept)\z/ } sort keys %h ), '>';
Condition0%0/4
$$u{"path"} // "/"
l!l
00
$h{"host"} // ""
l!l
00
MC/DC0%0/1
$$u{"path"} // "/"
$$u{"path"}
MC/DC0%0/1
$h{"host"} // ""
$h{"host"}
Truth table0%0/2
A
A= $$u{"path"}
Aresult
11
00
Truth table0%0/2
A
A= $h{"host"}
Aresult
11
00
374 0 push @v, ( map {"< $_"} @hl ), '<';
375 }
376 21 ▶ if ( $code && $code == 22 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code and $code == 22) 0 21 21
Condition33%1/3
$code and $code == 22
!ll&&!rl&&r
2100
MC/DC0%0/2
$code and $code == 22
$code $code == 22
Truth table33%1/3
A and B
A= $codeB= $code == 22
ABresult
0X0
100
111
377 0 push @out, @v;
378 0 ▶ push @out, "curl: (22) The requested URL returned error: $status" if !$silent || $show;
Branch: 1 branch
BranchTrueFalseTotal
if not $silent or $show 0 0 0
Condition0%0/3
not $silent or $show
l!l&&r!l&&!r
000
MC/DC0%0/2
not $silent or $show
not $silent $show
Truth table0%0/3
not(A) or B
A= not $silentB= $show
ABresult
1X1
011
000
379 0 ▶ push @out, _wout( $wfmt, { http_code => $status }, $url ) if defined $wfmt;
Branch: 1 branch
BranchTrueFalseTotal
if defined $wfmt 0 0 0
380 0 return ( join( "\n", @out ), 0 );
381 }
382 21 push @out, @v;
383 21 my $show_body = !$head;
384 21 ▶ if ( $head || $f{'-i'} || $f{'--include'} ) { push @out, @hl, '' }
Branch: 1 branch
BranchTrueFalseTotal
if ($head or $f{"-i"} or $f{"--include"}) 2 19 21
Condition66%4/6
$head or $f{"-i"} or $f{"--include"}
l!l&&r!l&&!r
2019
$head or $f{"-i"}
l!l&&r!l&&!r
2019
MC/DC33%1/3
$head or $f{"-i"} or $f{"--include"}
$head $f{"-i"} $f{"--include"}
Truth table50%2/4
A or B or C
A= $headB= $f{"-i"}C= $f{"--include"}
ABCresult
1XX1
01X1
0011
0000
385 21 ▶ my $b = $res->{body} // '';
Condition50%1/2
$$res{"body"} // ""
l!l
210
MC/DC0%0/1
$$res{"body"} // ""
$$res{"body"}
Truth table50%1/2
A
A= $$res{"body"}
Aresult
11
00
386 21 ▶ if ( defined $out_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $out_file) 6 15 21
387 0 ▶ if ( $out_file ne '/dev/null' && $out_file ne '-' ) { my ( $e, $ok ) = _linux()->can('_write_path')->( $dev, $out_file, $b, 0, $ctx ); return ( $e, 0 ) unless $ok }
Branch: 2 branches
BranchTrueFalseTotal
if ($out_file ne "/dev/null" and $out_file ne "-") 0 6 6
unless $ok 0 0 0
Condition33%1/3
$out_file ne "/dev/null" and $out_file ne "-"
!ll&&!rl&&r
600
MC/DC0%0/2
$out_file ne "/dev/null" and $out_file ne "-"
$out_file ne "/dev/null" $out_file ne "-"
Truth table33%1/3
A and B
A= $out_file ne "/dev/null"B= $out_file ne "-"
ABresult
0X0
100
111
388 6 ▶ $show_body = 0 unless $out_file eq '-';
Branch: 1 branch
BranchTrueFalseTotal
unless $out_file eq "-" 6 0 6
389 }
390 21 ▶ if ($show_body) { ( my $t = $b ) =~ s/\n\z//; push @out, $t if length $t }
Branch: 2 branches
BranchTrueFalseTotal
if ($show_body) 13 8 21
if length $t 13 0 13
391 21 ▶ if ( defined $wfmt ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $wfmt) 6 15 21
392 0 ▶ my ($loc) = map { $_->[1] } grep { lc( $_->[0] ) eq 'location' } @{ $res->{headers} || [] };
Condition50%1/2
$$res{'headers'} || []
l!l
60
MC/DC0%0/1
$$res{'headers'} || []
$$res{'headers'}
Truth table50%1/2
A
A= $$res{'headers'}
Aresult
11
00
393 6 ▶ my $w = _wout( $wfmt, { http_code => $status, redirect_url => $loc // '', ssl_verify_result => 0 }, $url );
Condition50%1/2
$loc // ""
l!l
06
MC/DC0%0/1
$loc // ""
$loc
Truth table50%1/2
A
A= $loc
Aresult
11
00
394 0 ▶ if ( @out && !$verbose && $show_body ) { $out[-1] .= $w } else { push @out, $w }
Branch: 1 branch
BranchTrueFalseTotal
if (@out and not $verbose and $show_body) { } 0 6 6
Condition33%2/6
@out and not $verbose and $show_body
!ll&&!rl&&r
600
@out and not $verbose
!ll&&!rl&&r
600
MC/DC0%0/3
@out and not $verbose and $show_body
@out not $verbose $show_body
Truth table25%1/4
A and not(B) and C
A= @outB= not $verboseC= $show_body
ABCresult
0XX0
10X0
1100
1111
395 }
396 21 ▶ pop @out while @out && $out[-1] eq '' && $head;
Branch: 1 branch
BranchTrueFalseTotal
@out and $out[-1] eq "" and $head and do { pop @out } 2 21 23
Condition66%4/6
@out and $out[-1] eq "" and $head
!ll&&!rl&&r
2102
@out and $out[-1] eq ""
!ll&&!rl&&r
0212
MC/DC33%1/3
@out and $out[-1] eq "" and $head
@out $out[-1] eq "" $head
Truth table50%2/4
A and B and C
A= @outB= $out[-1] eq ""C= $head
ABCresult
0XX0
10X0
1100
1111
397 21 return ( join( "\n", @out ), 1 );
398 }
399  
400 21 ▶sub _resp_headers {
Subroutine _resp_headers: called CC=3 SCAR=11.0
401 21 my ($res) = @_;
402 21 ▶ my @h = ( 'Server: ' . ( $res->{server} // 'nginx' ) ) x !!$res->{server};
Condition100%2/2
$$res{"server"} // "nginx"
l!l
201
MC/DC100%1/1
$$res{"server"} // "nginx"
$$res{"server"}
Truth table100%2/2
A
A= $$res{"server"}
Aresult
11
00
403 21 ▶ push @h, map {"$_->[0]: $_->[1]"} @{ $res->{headers} || [] };
Condition50%1/2
$$res{'headers'} || []
l!l
210
MC/DC0%0/1
$$res{'headers'} || []
$$res{'headers'}
Truth table50%1/2
A
A= $$res{'headers'}
Aresult
11
00
404 21 return @h;
405 }
406  
407 0 ▶sub _hname { my ($n) = @_; return join '-', map {ucfirst} split /-/, $n }
Subroutine _hname: not called CC=1 SCAR=6.9
408  
409 6 ▶sub _wout {
Subroutine _wout: called CC=2 SCAR=7.0
410 6 my ( $fmt, $v, $url ) = @_;
411 6 $fmt =~ s/\\n/\n/g;
412 6 $fmt =~ s/%\{url_effective\}/$url/g;
413 6 $fmt =~ s/%\{time_total\}/0.012000/g;
414 6 ▶ $fmt =~ s/%\{(\w+)\}/$v->{$1} \/\/ ''/ge;
Condition50%1/2
$$v{$1} // ""
l!l
60
MC/DC0%0/1
$$v{$1} // ""
$$v{$1}
Truth table50%1/2
A
A= $$v{$1}
Aresult
11
00
415 6 $fmt =~ s/\n\z//;
416 6 return $fmt;
417 }
418  
419 0 ▶sub _b64 { require MIME::Base64; return MIME::Base64::encode_base64( $_[0], '' ) }
Subroutine _b64: not called CC=1 SCAR=6.9
420  
421 5 1;
422  
423 __END__
« blib/lib/Langertha/Holmgang/Sim/Linux/Docker.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Storage.pm »