URI/_server.pm

filter: Statementstmt 99.1% 117 / 118 Branchbran 91.8% 68 / 74 Conditioncond 97.3% 37 / 38 MC/DCmcdc 95.2% 20 / 21 Subroutinesub 93.3% 14 / 15 Podpod 100% 8 / 8 totaltotal 96.3% 264 / 274 CC 51 SCAR 20.8
CC
51
Cov
97%
canonical
14.0
host
13.0
userinfo
6.0
CRAP 8.0
« URI/file/OS2.pm ↑ Summary URI/Split.pm »
1 package URI::_server;
2  
3 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 47 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 47 ▶use parent 'URI::_generic';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 47 ▶use URI::Escape qw(uri_unescape);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 47 our $VERSION = '5.40';
11  
12 921 ▶sub _uric_escape {
Subroutine _uric_escape: called CC=5 SCAR=16.1
13 921 my ($class, $str) = @_;
14 921 ▶ if ($str =~ m,^((?:$URI::scheme_re:)?)//([^/?\#]*)(.*)$,os) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ m[^((?:$URI::scheme_re:)?)//([^/?\#]*)(.*)$]so) 556 365 921
15 556 my ($scheme, $host, $rest) = ($1, $2, $3);
16 556 ▶ my $ui = $host =~ s/(.*@)// ? $1 : "";
Branch: 1 branch
BranchTrueFalseTotal
$host =~ s/(.*@)// ? : 38 518 556
17 556 ▶ my $port = $host =~ s/(:\d+)\z// ? $1 : "";
Branch: 1 branch
BranchTrueFalseTotal
$host =~ s/(:\d+)\z// ? : 33 523 556
18 556 ▶ if (_host_escape($host)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_host_escape($host)) 5 551 556
19 5 $str = "$scheme//$ui$host$port$rest";
20 }
21 }
22 921 return $class->SUPER::_uric_escape($str);
23 }
24  
25 594 ▶sub _host_escape {
Subroutine _host_escape: called CC=3 SCAR=11.0
26 594 return if URI::HAS_RESERVED_SQUARE_BRACKETS and $_[0] !~ /[^$URI::uric]/;
27 return
28 588 ▶ if !URI::HAS_RESERVED_SQUARE_BRACKETS and $_[0] !~ /[^$URI::uric4host]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /[^$URI::uric4host]/ 588 6 594
29 6 eval {
30 6 require URI::_idna;
31 6 $_[0] = URI::_idna::encode($_[0]);
32 };
33 6 ▶ return 0 if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 5 6
34 5 return 1;
35 }
36  
37 15 ▶sub as_iri {
Subroutine as_iri: called CC=5 SCAR=16.3
Pod documented
38 15 my $self = shift;
39 15 my $str = $self->SUPER::as_iri;
40 15 ▶ if ($str =~ /\bxn--/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\bxn--/) 5 10 15
41 5 ▶ if ($str =~ m,^((?:$URI::scheme_re:)?)//([^/?\#]*)(.*)$,os) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ m[^((?:$URI::scheme_re:)?)//([^/?\#]*)(.*)$]so) 5 0 5
42 5 my ($scheme, $host, $rest) = ($1, $2, $3);
43 5 ▶ my $ui = $host =~ s/(.*@)// ? $1 : "";
Branch: 1 branch
BranchTrueFalseTotal
$host =~ s/(.*@)// ? : 0 5 5
44 5 ▶ my $port = $host =~ s/(:\d+)\z// ? $1 : "";
Branch: 1 branch
BranchTrueFalseTotal
$host =~ s/(:\d+)\z// ? : 0 5 5
45 5 require URI::_idna;
46 5 $host = URI::_idna::decode($host);
47 5 $str = "$scheme//$ui$host$port$rest";
48 }
49 }
50 15 return $str;
51 }
52  
53 181 ▶sub userinfo {
Subroutine userinfo: called CC=6 SCAR=17.9
Pod documented
54 181 my $self = shift;
55 181 my $old = $self->authority;
56  
57 181 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 47 134 181
58 47 my $new = $old;
59 47 ▶ $new = "" unless defined $new;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new 0 47 47
60 47 $new =~ s/.*@//; # remove old stuff
61 47 my $ui = shift;
62 47 ▶ if (defined $ui) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ui) 43 4 47
63 43 $ui =~ s/([^$URI::uric4user])/ URI::Escape::escape_char($1)/ego;
64 43 $new = "$ui\@$new";
65 }
66 47 $self->authority($new);
67 }
68 181 ▶ return undef if !defined($old) || $old !~ /(.*)@/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $old and $old =~ /(.*)@/ 38 143 181
Condition100%3/3
defined $old and $old =~ /(.*)@/
!ll&&!rl&&r
335143
MC/DC100%2/2
defined $old and $old =~ /(.*)@/
defined $old $old =~ /(.*)@/
Truth table100%3/3
A and B
A= defined $oldB= $old =~ /(.*)@/
ABresult
0X0
100
111
69 143 return $1;
70 }
71  
72 529 ▶sub host {
Subroutine host: called CC=13 SCAR=25.7
Pod documented
73 529 my $self = shift;
74 529 my $old = $self->authority;
75 529 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 39 490 529
76 39 my $tmp = $old;
77 39 ▶ $tmp = "" unless defined $tmp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tmp 4 35 39
78 39 ▶ my $ui = ($tmp =~ /(.*@)/) ? $1 : "";
Branch: 1 branch
BranchTrueFalseTotal
$tmp =~ /(.*@)/ ? : 17 22 39
79 39 ▶ my $port = ($tmp =~ /(:\d+)$/) ? $1 : "";
Branch: 1 branch
BranchTrueFalseTotal
$tmp =~ /(:\d+)$/ ? : 15 24 39
80 39 my $new = shift;
81 39 ▶ $new = "" unless defined $new;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new 1 38 39
82 39 ▶ if (length $new) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $new) 38 1 39
83 38 $new =~ s/[@]/%40/g; # protect @
84 38 ▶ if ($new =~ /^[^:]*:\d*\z/ || $new =~ /]:\d*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new =~ /^[^:]*:\d*\z/ or $new =~ /]:\d*\z/) 4 34 38
Condition100%3/3
$new =~ /^[^:]*:\d*\z/ or $new =~ /]:\d*\z/
l!l&&r!l&&!r
1334
MC/DC100%2/2
$new =~ /^[^:]*:\d*\z/ or $new =~ /]:\d*\z/
$new =~ /^[^:]*:\d*\z/ $new =~ /]:\d*\z/
Truth table100%3/3
A or B
A= $new =~ /^[^:]*:\d*\z/B= $new =~ /]:\d*\z/
ABresult
1X1
011
000
85 4 ▶ $new =~ s/(:\d*)\z// || die "Assert";
Branch: 1 branch
BranchTrueFalseTotal
$new =~ s/(:\d*)\z// or die "Assert" 4 0 4
86 4 $port = $1;
87 }
88 38 ▶ $new = "[$new]" if $new =~ /:/ && $new !~ /^\[/; # IPv6 address
Branch: 1 branch
BranchTrueFalseTotal
if $new =~ /:/ and not $new =~ /^\[/ 11 27 38
Condition100%3/3
$new =~ /:/ and not $new =~ /^\[/
!ll&&!rl&&r
23411
MC/DC100%2/2
$new =~ /:/ and not $new =~ /^\[/
$new =~ /:/ not $new =~ /^\[/
Truth table100%3/3
A and not(B)
A= $new =~ /:/B= not $new =~ /^\[/
ABresult
0X0
100
111
89 38 _host_escape($new);
90 }
91 39 $self->authority("$ui$new$port");
92 }
93 529 ▶ return undef unless defined $old;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $old 79 450 529
94 450 $old =~ s/.*@//;
95 450 $old =~ s/:\d*$//; # remove the port
96 450 $old =~ s{^\[(.*)\]$}{$1}; # remove brackets around IPv6 (RFC 3986 3.2.2)
97 450 return uri_unescape($old);
98 }
99  
100 5 ▶sub ihost {
Subroutine ihost: called CC=2 SCAR=6.9
Pod documented
101 5 my $self = shift;
102 5 my $old = $self->host(@_);
103 5 ▶ if ($old =~ /(^|\.)xn--/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old =~ /(^|\.)xn--/) 3 2 5
104 3 require URI::_idna;
105 3 $old = URI::_idna::decode($old);
106 }
107 5 return $old;
108 }
109  
110 567 ▶sub _port {
Subroutine _port: called CC=5 SCAR=16.1
111 567 my $self = shift;
112 567 my $old = $self->authority;
113 567 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 61 506 567
114 61 my $new = $old;
115 61 $new =~ s/:\d*$//;
116 61 my $port = shift;
117 61 ▶ $new .= ":$port" if defined $port;
Branch: 1 branch
BranchTrueFalseTotal
if defined $port 36 25 61
118 61 $self->authority($new);
119 }
120 567 ▶ return $1 if defined($old) && $old =~ /:(\d*)$/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $old and $old =~ /:(\d*)$/ 115 452 567
Condition100%3/3
defined $old and $old =~ /:(\d*)$/
!ll&&!rl&&r
77375115
MC/DC100%2/2
defined $old and $old =~ /:(\d*)$/
defined $old $old =~ /:(\d*)$/
Truth table100%3/3
A and B
A= defined $oldB= $old =~ /:(\d*)$/
ABresult
0X0
100
111
121 452 return;
122 }
123  
124 135 ▶sub port {
Subroutine port: called CC=3 SCAR=11.0
Pod documented
125 135 my $self = shift;
126 135 my $port = $self->_port(@_);
127 135 ▶ $port = $self->default_port if !defined($port) || $port eq "";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $port or $port eq "" 80 55 135
Condition100%3/3
not defined $port or $port eq ""
l!l&&r!l&&!r
671355
MC/DC100%2/2
not defined $port or $port eq ""
not defined $port $port eq ""
Truth table100%3/3
not(A) or B
A= not defined $portB= $port eq ""
ABresult
1X1
011
000
128 135 $port;
129 }
130  
131 10 ▶sub host_port {
Subroutine host_port: called CC=4 SCAR=13.9
Pod documented
132 10 my $self = shift;
133 10 my $old = $self->authority;
134 10 ▶ $self->host(shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 7 10
135 10 ▶ return undef unless defined $old;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $old 0 10 10
136 10 $old =~ s/.*@//; # zap userinfo
137 10 $old =~ s/:$//; # empty port should be treated the same a no port
138 10 ▶ $old .= ":" . $self->port unless $old =~ /:\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $old =~ /:\d+$/ 6 4 10
139 10 $old;
140 }
141  
142  
143 0 ▶sub default_port {undef}
Subroutine default_port: not called CC=1 SCAR=6.9
Pod documented
144  
145 422 ▶sub canonical {
Subroutine canonical: called CC=14 SCAR=26.4
Pod documented
146 422 my $self = shift;
147 422 my $other = $self->SUPER::canonical;
148 422 ▶ my $host = $other->host || "";
Condition100%2/2
$other->host || ''
l!l
34874
MC/DC100%1/1
$other->host || ''
$other->host
Truth table100%2/2
A
A= $other->host
Aresult
11
00
149 422 my $port = $other->_port;
150 422 my $uc_host = $host =~ /[A-Z]/;
151 422 ▶ my $def_port
Condition100%6/6
defined $port && ($port eq '' || $port == $self->default_port)
!ll&&!rl&&r
3842216
$port eq "" or $port == $self->default_port
l!l&&r!l&&!r
21422
MC/DC100%3/3
defined $port && ($port eq '' || $port == $self->default_port)
defined $port $port eq "" $port == $self->default_port
Truth table100%4/4
A && B or C
A= defined $portB= $port eq ""C= $port == $self->default_port
ABCresult
0XX0
1000
11X1
1011
152 = defined($port) && ($port eq "" || $port == $self->default_port);
153  
154 # strip leading zeros from non-default ports (e.g. 08080 -> 8080)
155 422 ▶ my $norm_port
Condition88%8/9
!$def_port && defined $port && $port ne '' && $port =~ /^0\d/
!ll&&!rl&&r
400139
not $def_port and defined $port and $port ne ""
!ll&&!rl&&r
400022
not $def_port and defined $port
!ll&&!rl&&r
1638422
MC/DC75%3/4
!$def_port && defined $port && $port ne '' && $port =~ /^0\d/
not $def_port defined $port $port ne "" $port =~ /^0\d/
Truth table80%4/5
not(A) and B and C && D
A= not $def_portB= defined $portC= $port ne ""D= $port =~ /^0\d/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
156 = !$def_port && defined($port) && $port ne "" && $port =~ /^0\d/;
157 422 ▶ if ($uc_host || $def_port || $norm_port) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uc_host or $def_port or $norm_port) 35 387 422
Condition100%6/6
$uc_host or $def_port or $norm_port
l!l&&r!l&&!r
269387
$uc_host or $def_port
l!l&&r!l&&!r
1511396
MC/DC100%3/3
$uc_host or $def_port or $norm_port
$uc_host $def_port $norm_port
Truth table100%4/4
A or B or C
A= $uc_hostB= $def_portC= $norm_port
ABCresult
1XX1
01X1
0011
0000
158 35 ▶ $other = $other->clone if $other == $self;
Branch: 1 branch
BranchTrueFalseTotal
if $other == $self 23 12 35
159 35 ▶ $other->host(lc $host) if $uc_host;
Branch: 1 branch
BranchTrueFalseTotal
if $uc_host 15 20 35
160 35 ▶ $other->port(undef) if $def_port;
Branch: 1 branch
BranchTrueFalseTotal
if $def_port 16 19 35
161 35 ▶ $other->_port(int($port)) if $norm_port;
Branch: 1 branch
BranchTrueFalseTotal
if $norm_port 9 26 35
162 }
163 422 $other;
164 }
165  
166 47 1;
« URI/file/OS2.pm ↑ Summary URI/Split.pm »