| 1 | package URI::_generic; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 52 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 52 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 52 | ▶ | use parent qw(URI URI::_query); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 52 | ▶ | use URI::Escape qw(uri_unescape); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 52 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 52 | our $VERSION = '5.40'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 52 | my $ACHAR = URI::HAS_RESERVED_SQUARE_BRACKETS ? $URI::uric : $URI::uric4host; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 52 | $ACHAR =~ s,\\[/?],,g; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 52 | my $PCHAR = $URI::uric; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 52 | $PCHAR =~ s,\\[?],,g; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 365 | ▶ | sub _no_scheme_ok {1} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_no_scheme_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 52 | our $IPv6_re; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 367 | ▶ | sub _looks_like_raw_ip6_address { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_looks_like_raw_ip6_address: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 367 | my $addr = shift; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 367 | ▶ | if (!$IPv6_re) { #-- lazy / runs once / use Regexp::IPv6 if installed | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 26 | require Regexp::IPv6; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | Regexp::IPv6->import(qw($IPv6_re)); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 26 | ▶ | || do { $IPv6_re = qr/[:0-9a-f]{3,}/; }; #-- fallback: unambitious guess | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 367 | ▶ | return 0 unless $addr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 367 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | if $addr =~ tr/:/:/ | ||||||||||||||||||||||||||||||||||||||||||
| 37 | < 2; #-- fallback must not create false positive for IPv4:Port = 0:0 | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 28 | ▶ | return 1 if $addr =~ /^$IPv6_re$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 26 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 2691 | ▶ | sub authority { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authority: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 2691 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 2691 | ▶ | $$self =~ m,^((?:$URI::scheme_re:)?)(?://([^/?\#]*))?(.*)$,os or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 2691 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 478 | my $auth = shift; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 478 | $$self = $1; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 478 | my $rest = $3; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 478 | ▶ | if (defined $auth) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 397 | $auth =~ s/([^$ACHAR])/ URI::Escape::escape_char($1)/ego; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 397 | ▶ | if (my ($user, $host) = $auth =~ /^(.*@)?([^@]+)$/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | { #-- special escape userinfo part | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 367 | ▶ | $user ||= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$user ||= ""
MC/DC100%1/1
$user ||= ""
$user
Truth table100%2/2
A
A= $user
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 367 | $user | |||||||||||||||||||||||||||||||||||||||||
| 57 | 76 | =~ s/([^$URI::uric4user])/ URI::Escape::escape_char($1)/ego; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 367 | $user =~ s/%40$/\@/; # recover final '@' | |||||||||||||||||||||||||||||||||||||||||
| 59 | 367 | ▶ | $host = "[$host]" if _looks_like_raw_ip6_address($host); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 367 | $auth = $user . $host; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 397 | utf8::downgrade($auth); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 397 | $$self .= "//$auth"; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 478 | _check_path($rest, $$self); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 478 | $$self .= $rest; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 2691 | $2; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1505 | ▶ | sub path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1505 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 1505 | ▶ | $$self =~ m,^((?:[^:/?\#]+:)?(?://[^/?\#]*)?)([^?\#]*)(.*)$,s or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 1505 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 402 | $$self = $1; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 402 | my $rest = $3; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 402 | my $new_path = shift; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 402 | ▶ | $new_path = "" unless defined $new_path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 402 | $new_path =~ s/([^$PCHAR])/ URI::Escape::escape_char($1)/ego; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 402 | utf8::downgrade($new_path); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 402 | _check_path($new_path, $$self); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 402 | $$self .= $new_path . $rest; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 1505 | $2; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 58 | ▶ | sub path_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_query: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 58 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 58 | ▶ | $$self =~ m,^((?:[^:/?\#]+:)?(?://[^/?\#]*)?)([^\#]*)(.*)$,s or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 58 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | $$self = $1; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | my $rest = $3; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 3 | my $new_path = shift; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 3 | ▶ | $new_path = "" unless defined $new_path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 3 | $new_path =~ s/([^$URI::uric])/ URI::Escape::escape_char($1)/ego; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | utf8::downgrade($new_path); | |||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | _check_path($new_path, $$self); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | $$self .= $new_path . $rest; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 58 | $2; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 883 | ▶ | sub _check_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_path: called CC=10 SCAR=26.5
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 883 | my ($path, $pre) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 883 | my $prefix; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 883 | ▶ | if ($pre =~ m,/,) { # authority present | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 713 | ▶ | $prefix = "/" if length($path) && $path !~ m,^[/?\#],; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $path and not $path =~ m[^[/?\#]]
MC/DC100%2/2
length $path and not $path =~ m[^[/?\#]]
length $path
not $path =~ m[^[/?\#]]
Truth table100%3/3
A and not(B)
A= length $pathB= not $path =~ m[^[/?\#]]
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 170 | ▶ | if ($path =~ m,^//,) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | Carp::carp("Path starting with double slash is confusing") if $^W; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | ▶ | elsif (!length($pre) && $path =~ m,^[^:/?\#]+:,) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not length $pre and $path =~ m[^[^:/?\#]+:]
MC/DC0%0/2
not length $pre and $path =~ m[^[^:/?\#]+:]
not length $pre
$path =~ m[^[^:/?\#]+:]
Truth table66%2/3
not(A) and B
A= not length $preB= $path =~ m[^[^:/?\#]+:]
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | Carp::carp("Path might look like scheme, './' prepended") if $^W; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $prefix = "./"; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 883 | ▶ | substr($_[0], 0, 0) = $prefix if defined $prefix; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 97 | ▶ | sub path_segments { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_segments: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 97 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 97 | my $path = $self->path; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 97 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | my @arg = @_; # make a copy | |||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | for (@arg) { | |||||||||||||||||||||||||||||||||||||||||
| 129 | 21 | ▶ | if (ref($_)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | my @seg = @$_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | $seg[0] =~ s/%/%25/g; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | for (@seg) { s/;/%3B/g; } | |||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | $_ = join(";", @seg); | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 20 | s/%/%25/g; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 20 | s/;/%3B/g; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 21 | s,/,%2F,g; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 6 | $self->path(join("/", @arg)); | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 97 | ▶ | return $path unless wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 88 | ▶ | map { /;/ ? $self->_split_segment($_) : uri_unescape($_) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | split('/', $path, -1); | ||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | ▶ | sub _split_segment { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_segment: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 4 | require URI::_segment; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | URI::_segment->new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 286 | ▶ | sub abs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
abs: called CC=26 SCAR=32.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 286 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 286 | ▶ | my $base = shift || Carp::croak("Missing base argument"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || Carp::croak('Missing base argument')
MC/DC0%0/1
shift() || Carp::croak('Missing base argument')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 286 | ▶ | if (my $scheme = $self->scheme) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 29 | ▶ | return $self unless $URI::ABS_ALLOW_RELATIVE_SCHEME; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 10 | ▶ | $base = URI->new($base) unless ref $base; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 10 | ▶ | return $self unless $scheme eq $base->scheme; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 264 | ▶ | $base = URI->new($base) unless ref $base; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 264 | my $abs = $self->clone; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 264 | $abs->scheme($base->scheme); | |||||||||||||||||||||||||||||||||||||||||
| 169 | 264 | ▶ | return $abs if $$self =~ m,^(?:$URI::scheme_re:)?//,o; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 253 | $abs->authority($base->authority); | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 253 | my $path = $self->path; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 253 | ▶ | return $abs if $path =~ m,^/,; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 234 | ▶ | if (!length($path)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 27 | my $abs = $base->clone; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 27 | my $query = $self->query; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 27 | ▶ | $abs->query($query) if defined $query; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 27 | my $fragment = $self->fragment; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 27 | ▶ | $abs->fragment($fragment) if defined $fragment; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 27 | return $abs; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 207 | my $p = $base->path; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 207 | $p =~ s,[^/]+$,,; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 207 | $p .= $path; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 207 | my @p = split('/', $p, -1); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 207 | ▶ | shift(@p) if @p && !length($p[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@p and not length $p[0]
MC/DC50%1/2
@p and not length $p[0]
@p
not length $p[0]
Truth table66%2/3
A and not(B)
A= @pB= not length $p[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 207 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 207 | ▶ | while ($i < @p) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | #print "$i ", join("/", @p), " ($p[$i])\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 664 | ▶ | if ($p[$i - 1] eq ".") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 35 | splice(@p, $i - 1, 1); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 35 | ▶ | $i-- if $i > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | ▶ | elsif ($p[$i] eq ".." && $p[$i - 1] ne "..") { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$p[$i] eq ".." and $p[$i - 1] ne ".."
MC/DC100%2/2
$p[$i] eq ".." and $p[$i - 1] ne ".."
$p[$i] eq ".."
$p[$i - 1] ne ".."
Truth table100%3/3
A and B
A= $p[$i] eq ".."B= $p[$i - 1] ne ".."
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 108 | splice(@p, $i - 1, 2); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 108 | ▶ | if ($i > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 78 | $i--; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 78 | ▶ | push(@p, "") if $i == @p; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 521 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 207 | ▶ | $p[-1] = "" if @p && $p[-1] eq "."; # trailing "/." | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@p and $p[-1] eq "."
MC/DC100%2/2
@p and $p[-1] eq "."
@p
$p[-1] eq "."
Truth table100%3/3
A and B
A= @pB= $p[-1] eq "."
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 207 | ▶ | if ($URI::ABS_REMOTE_LEADING_DOTS) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 3 | ▶ | shift @p while @p && $p[0] =~ /^\.\.?$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@p and $p[0] =~ /^\.\.?$/
MC/DC50%1/2
@p and $p[0] =~ /^\.\.?$/
@p
$p[0] =~ /^\.\.?$/
Truth table66%2/3
A and B
A= @pB= $p[0] =~ /^\.\.?$/
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 207 | $abs->path("/" . join("/", @p)); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 207 | $abs; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | # The opposite of $url->abs. Return a URI which is as relative as possible | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 73 | ▶ | sub rel { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rel: called CC=19 SCAR=29.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 73 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 73 | ▶ | my $base = shift || Carp::croak("Missing base argument"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || Carp::croak('Missing base argument')
MC/DC0%0/1
shift() || Carp::croak('Missing base argument')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 73 | my $rel = $self->clone; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 73 | ▶ | $base = URI->new($base) unless ref $base; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | #my($scheme, $auth, $path) = @{$rel}{qw(scheme authority path)}; | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 73 | my $scheme = $rel->scheme; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 73 | my $auth = $rel->canonical->authority; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 73 | my $path = $rel->path; | |||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 73 | ▶ | if (!defined($scheme) && !defined($auth)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $scheme or defined $auth
MC/DC0%0/2
defined $scheme or defined $auth
defined $scheme
defined $auth
Truth table33%1/3
A or B
A= defined $schemeB= defined $auth
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | # it is already relative | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return $rel; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | #my($bscheme, $bauth, $bpath) = @{$base}{qw(scheme authority path)}; | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 73 | my $bscheme = $base->scheme; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 73 | my $bauth = $base->canonical->authority; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 73 | my $bpath = $base->path; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 73 | for ($bscheme, $bauth, $auth) { | |||||||||||||||||||||||||||||||||||||||||
| 240 | 219 | ▶ | $_ = '' unless defined; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 73 | ▶ | unless ($scheme eq $bscheme && $auth eq $bauth) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$scheme eq $bscheme and $auth eq $bauth
MC/DC100%2/2
$scheme eq $bscheme and $auth eq $bauth
$scheme eq $bscheme
$auth eq $bauth
Truth table100%3/3
A and B
A= $scheme eq $bschemeB= $auth eq $bauth
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # different location, can't make it relative | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 5 | return $rel; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 68 | ▶ | for ($path, $bpath) { $_ = "/$_" unless m,^/,; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | # Make it relative by eliminating scheme and authority | ||||||||||||||||||||||||||||||||||||||||||
| 252 | # (empty the path first so a leading "//" can't be reparsed as authority) | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 68 | $rel->path(q{}); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 68 | $rel->scheme(undef); | |||||||||||||||||||||||||||||||||||||||||
| 255 | 68 | $rel->authority(undef); | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | # This loop is based on code from Nicolai Langfeldt <janl@ifi.uio.no>. | ||||||||||||||||||||||||||||||||||||||||||
| 258 | # First we calculate common initial path components length ($li). | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 68 | my $li = 1; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 68 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 261 | 148 | my $i = index($path, '/', $li); | |||||||||||||||||||||||||||||||||||||||||
| 262 | last | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 148 | ▶ | if $i < 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$i < 0 or $i != index($bpath, "/", $li) or substr($path, $li, $i - $li) ne substr($bpath, $li, $i - $li)
$i < 0 or $i != index($bpath, "/", $li)
MC/DC100%3/3
$i < 0 or $i != index($bpath, "/", $li) or substr($path, $li, $i - $li) ne substr($bpath, $li, $i - $li)
$i < 0
$i != index($bpath, "/", $li)
substr($path, $li, $i - $li) ne substr($bpath, $li, $i - $li)
Truth table100%4/4
A or B or C
A= $i < 0B= $i != index($bpath, "/", $li)C= substr($path, $li, $i - $li) ne substr($bpath, $li, $i - $li)
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | || $i != index($bpath, '/', $li) | ||||||||||||||||||||||||||||||||||||||||||
| 265 | || substr($path, $li, $i - $li) ne substr($bpath, $li, $i - $li); | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 80 | $li = $i + 1; | |||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | # then we nuke it from both paths | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 68 | substr($path, 0, $li) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 68 | substr($bpath, 0, $li) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 68 | ▶ | if ($path eq $bpath && defined($rel->fragment) && !defined($rel->query)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$path eq $bpath and defined $rel->fragment and not defined $rel->query
$path eq $bpath and defined $rel->fragment
MC/DC100%3/3
$path eq $bpath and defined $rel->fragment and not defined $rel->query
$path eq $bpath
defined $rel->fragment
not defined $rel->query
Truth table100%4/4
A and B and not(C)
A= $path eq $bpathB= defined $rel->fragmentC= not defined $rel->query
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 2 | $rel->path(""); | |||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 277 | # Add one "../" for each path component left in the base path | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 66 | $path = ('../' x $bpath =~ tr{/}{/}) . $path; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 66 | ▶ | $path = "./" if $path eq ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | # leading "/" reads as an absolute path, "//" as an authority | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 66 | ▶ | $path = "./$path" if $path =~ m{^/}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 66 | $rel->path($path); | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 68 | $rel; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 52 | 1; | |||||||||||||||||||||||||||||||||||||||||