| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | Quiq::Url - Operationen im Zusammenhang mit URLs | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | L<Quiq::Object> | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | Die Klasse definiert Operationen, die im Zusammenhang mit URLs | ||||||||||||||||||||||||||||||||||||||||||
| 16 | nützlich sind. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | package Quiq::Url; | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | ▶ | use base qw/Quiq::Object/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | our $VERSION = '1.240'; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 5 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | ▶ | use Quiq::Array; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | ▶ | use Quiq::Option; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =head2 Konstruktor | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | =head3 new() - Instantiiere Objekt | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | $u = $class->new; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | Instantiiere ein Objekt der Klasse und liefere eine Referenz auf | ||||||||||||||||||||||||||||||||||||||||||
| 50 | dieses Objekt zurück. Da die Klasse ausschließlich Klassenmethoden | ||||||||||||||||||||||||||||||||||||||||||
| 51 | enthält, hat das Objekt lediglich die Funktion, eine abkürzende | ||||||||||||||||||||||||||||||||||||||||||
| 52 | Aufrufschreibweise zu ermöglichen. | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | return bless \(my $dummy),$class; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | =head2 Klassenmethoden | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | =head3 href() - Erzeuge URL | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | $url = $this->href($baseUrl,@keyVal); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | =item $baseUrl | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | (String) URL bis zum Query-String (ohne Fragezeichen) | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | =item @keyVal | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | Liste der Query-String Parameter | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | =head4 Options | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | =item -append => $queryString | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | Hänge den Querystring $querystring (unverändert) an den URL an. | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | String | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | Erzeuge einen URL der Form C<< $baseUrl?<querystring> >> und liefere diesen | ||||||||||||||||||||||||||||||||||||||||||
| 104 | zurück. | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub href { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
href: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my ($this,$url) = splice @_,0,2; | |||||||||||||||||||||||||||||||||||||||||
| 112 | # @_: @keyVal | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $queryStr = $this->queryEncode(@_); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($queryStr) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $url .= "?$queryStr"; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | return $url; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | =head3 encode() - Kodiere Zeichenkette | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | $encStr = $this->encode($str); | ||||||||||||||||||||||||||||||||||||||||||
| 129 | $encStr = $this->encode($str,$encoding); | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | =item $str | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | Die Zeichenkette, die kodiert wird. | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | =item $encoding (Default: 'utf-8') | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | Das Encoding, in dem die Zeichenkette encodiert werden soll. | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | String | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | Kodiere die Zeichenkette $str nach MIME-Type | ||||||||||||||||||||||||||||||||||||||||||
| 152 | "application/x-www-form-urlencoded" und liefere die resultierende | ||||||||||||||||||||||||||||||||||||||||||
| 153 | Zeichenkette zurück. | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | In der Zeichenkette werden alle Zeichen außer | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | * - . _ + 0-9 A-Z a-z | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | durch eine Folge von | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | %xx | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | ersetzt, wobei die xx dem Hexadezimalwert des betreffenden | ||||||||||||||||||||||||||||||||||||||||||
| 164 | Bytes im Encoding des Zeichens entspricht. | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 99 | ▶ | sub encode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 99 | my ($this,$str) = splice @_,0,2; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 99 | ▶ | my $encoding = shift // 'utf-8'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // "utf-8"
MC/DC100%1/1
shift() // "utf-8"
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 99 | ▶ | if (!defined $str) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 3 | return ''; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 96 | $str = Encode::encode($encoding,$str); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 96 | $str =~ s|([^-*._0-9A-Za-z+])|sprintf('%%%02X',ord $1)|eg; | |||||||||||||||||||||||||||||||||||||||||
| 179 | # $str =~ s|%20|+|g; | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 96 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | =head3 decode() - Dekodiere Zeichenkette | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | $str = $this->decode($encStr); | ||||||||||||||||||||||||||||||||||||||||||
| 191 | $str = $this->decode($encStr,$encoding); | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | =item $str | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | Die Zeichenkette, die dekodiert wird. | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | =item $encoding (Default: 'utf-8') | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | Das Encoding, in dem die Zeichenkette encodiert ist. | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | String | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | Dekodiere die "application/x-www-form-urlencoded" codierte | ||||||||||||||||||||||||||||||||||||||||||
| 214 | Zeichenkette $encStr und liefere die resultierende Zeichenkette | ||||||||||||||||||||||||||||||||||||||||||
| 215 | zurück. | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 33 | ▶ | sub decode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 33 | my ($this,$str) = splice @_,0,2; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 33 | ▶ | my $encoding = shift // 'utf-8'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // "utf-8"
MC/DC100%1/1
shift() // "utf-8"
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 33 | ▶ | if (!defined $str) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | # $str =~ tr/+/ /; | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 33 | $str =~ s/%([\dA-F]{2})/chr hex $1/egi; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 33 | return Encode::decode($encoding,$str); | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | =head3 queryEncode() - Kodiere Querystring | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | $queryStr = $this->queryEncode(@opt,@keyVal); | ||||||||||||||||||||||||||||||||||||||||||
| 242 | $queryStr = $this->queryEncode($initialChar,@opt,@keyVal); | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | =head4 Alias | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | qE() | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | =item @keyVal | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | Liste der Schlüssel/Wert-Paare, die URL-kodiert werden sollen. | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | =item $initialChar | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | Zeichen, das der URL-Kodierten Zeichenkette vorangestellt werden | ||||||||||||||||||||||||||||||||||||||||||
| 259 | soll. Dies ist, wenn bentigt, typischweise ein Fragezeichen (?). | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | =head4 Options | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | =item -append => $queryString | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | Hänge den Querystring $querystring (unverändert) an den URL an. | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | =item -encoding => $encoding (Default: 'utf-8') | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | Das Encoding, in dem die Zeichenkette encodiert werden soll. | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | =item -null => $bool (Default: 0) | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | Kodiere auch Schlüssel/Wert-Paare mit leerem Wert (undef oder ''). | ||||||||||||||||||||||||||||||||||||||||||
| 278 | Per Default werden diese weggelassen. | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | =item -separator => $char (Default: '&') | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | Verwende $char als Trennzeichen zwischen den Schlüssel/Wert-Paaren. | ||||||||||||||||||||||||||||||||||||||||||
| 283 | Mögliche Werte sind '&' und ';'. | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | String | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | Kodiere die Schlüssel/Wert-Paare in @keyVal gemäß MIME-Type | ||||||||||||||||||||||||||||||||||||||||||
| 294 | "application/x-www-form-urlencoded" und füge sie zu einem Query String | ||||||||||||||||||||||||||||||||||||||||||
| 295 | zusammen. | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | =head4 Examples | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | Querystring mit Kaufmanns-Und als Trennzeichen: | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | $url = Quiq::Url->queryEncode(a=>1,b=>2,c=>3); | ||||||||||||||||||||||||||||||||||||||||||
| 302 | => | ||||||||||||||||||||||||||||||||||||||||||
| 303 | a=1&b=2&c=3 | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | Querystring mit Semikolon als Trennzeichen: | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | $url = Quiq::Url->queryEncode(-separator=>';',d=>4,e=>5); | ||||||||||||||||||||||||||||||||||||||||||
| 308 | => | ||||||||||||||||||||||||||||||||||||||||||
| 309 | d=4;e=5 | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | Querystring mit einleitendem Fragezeichen: | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | $url = Quiq::Url->queryEncode('?',a=>1,b=>2,c=>3); | ||||||||||||||||||||||||||||||||||||||||||
| 314 | => | ||||||||||||||||||||||||||||||||||||||||||
| 315 | ?a=1&b=2&c=3 | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | =head4 Details | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | Als Trennzeichen zwischen den Paaren wird per Default ein | ||||||||||||||||||||||||||||||||||||||||||
| 320 | Kaufmanns-Und (&) verwendet: | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | key1=val1&key2=val2&...&keyN=valN | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | Ist der erste Parameter ein Fragezeichen (?), wird dieses dem | ||||||||||||||||||||||||||||||||||||||||||
| 325 | Query String vorangestellt: | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | ?key1=val1&key2=val2&...&keyN=valN | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | Das Fragezeichen ist für die URL-Generierung nützlich, das Semikolon | ||||||||||||||||||||||||||||||||||||||||||
| 330 | und das Kaufmanns-Und für die Konkatenation von Querystrings. | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | Ist der Wert eines Schlüssels eine Arrayreferenz, wird für | ||||||||||||||||||||||||||||||||||||||||||
| 333 | jedes Arrayelement ein eigenes Schlüssel/Wert-Paar erzeugt: | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | a => [1,2,3] | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | wird zu | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | a=1&a=2&a=3 | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 13 | ▶ | sub queryEncode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
queryEncode: called CC=17 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 13 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 347 | # @_: '?' oder '&' oder ';' | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 13 | my $str = ''; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 13 | my $initialChar = ''; | |||||||||||||||||||||||||||||||||||||||||
| 351 | # if (length($_[0]) == 1 && $_[0] =~ /[&;?]/) { | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 13 | ▶ | if (@_%2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | # Einleitungszeichen | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 3 | $initialChar = shift; | |||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | # Direktiven | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 13 | my $append => undef; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 13 | my $encoding = 'utf-8', | |||||||||||||||||||||||||||||||||||||||||
| 361 | my $null = 0; | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 13 | my $separator = '&'; | |||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | # Query-String generieren | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 13 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 13 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 47 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 47 | ▶ | if (substr($key,0,1) eq '-') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | # Optionen | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 4 | ▶ | if ($key eq '-append') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | $append = shift; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | elsif ($key eq '-encoding') { | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | $encoding = shift; | |||||||||||||||||||||||||||||||||||||||||
| 378 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | elsif ($key eq '-null') { | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 2 | $null = shift; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | elsif ($key eq '-separator') { | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | $separator = shift; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 43 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 43 | ▶ | for my $val (ref $val? @$val: $val) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 53 | ▶ | if (!$null && (!defined $val or $val eq '')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $null and !defined($val) || $val eq ""
not defined $val or $val eq ""
MC/DC100%3/3
not $null and !defined($val) || $val eq ""
not $null
not defined $val
$val eq ""
Truth table100%4/4
not(A) and not(B) or C
A= not $nullB= not defined $valC= $val eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | # leere Werte übergehen | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 47 | ▶ | if ($i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 35 | $str .= $separator; | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 47 | $str .= $this->encode($key,$encoding); | |||||||||||||||||||||||||||||||||||||||||
| 400 | 47 | $str .= '='; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 47 | $str .= $this->encode($val,$encoding); | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 13 | ▶ | if ($append) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | if ($str) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $str .= $separator; | |||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $str .= $append; | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 13 | ▶ | return $i? "$initialChar$str": $str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | { | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 5 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 5 | *qE = \&queryEncode; | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | =head3 queryDecode() - Dekodiere Querystring | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | @arr | $arr = $this->queryDecode($queryStr); | ||||||||||||||||||||||||||||||||||||||||||
| 426 | @arr | $arr = $this->queryDecode($queryStr,$encoding); | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | =item $queryStr | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | Querystring, der dekodiert werden soll. | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | =item $encoding (Default: 'utf-8') | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | Das Encoding, in dem der Querystring encodiert ist. | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | Liste der dekodierten Schüssel/Wert-Paare. Im Skalarkontext | ||||||||||||||||||||||||||||||||||||||||||
| 445 | eine Referenz auf die Liste. | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | Dekodiere den Querystring $queryStr und liefere die resultierende | ||||||||||||||||||||||||||||||||||||||||||
| 450 | Liste von Schlüssel/Wert-Paaren zurück. Im Skalarkontext liefere | ||||||||||||||||||||||||||||||||||||||||||
| 451 | eine Referenz auf die Liste. | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | Die Schlüssel/Wert-Paare können per & oder ; getrennt sein. | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 6 | ▶ | sub queryDecode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
queryDecode: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | 6 | my ($this,$str) = splice @_,0,2; | |||||||||||||||||||||||||||||||||||||||||
| 461 | 6 | ▶ | my $encoding = shift // 'utf-8'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // "utf-8"
MC/DC100%1/1
shift() // "utf-8"
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 6 | my $arr = Quiq::Array->new; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 6 | for (split /[&;]/,$str) { | |||||||||||||||||||||||||||||||||||||||||
| 465 | 11 | ▶ | next if !$_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | 11 | my ($key,$val) = split /=/; | |||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 11 | $key = $this->decode($key,$encoding); | |||||||||||||||||||||||||||||||||||||||||
| 469 | 11 | $val = $this->decode($val,$encoding); | |||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 11 | push @$arr,$key,$val; | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 6 | ▶ | return wantarray? @$arr: $arr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | =head3 split() - Zerlege URL in seine Bestandteile | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | ($schema,$user,$passw,$host,$port,$path,$query,$fragment,@opt) = | ||||||||||||||||||||||||||||||||||||||||||
| 484 | $this->split($url); | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | =head4 Options | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | =item -defaultSchema => $schema (Default: undef) | ||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | Füge Defaultschema hinzu, falls keins angegeben ist. | ||||||||||||||||||||||||||||||||||||||||||
| 493 | Beispiel: -defaultSchema=>'http://' | ||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||
| 495 | =item -debug => $bool (Default: 0) | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | Gib die Zerlegung auf STDOUT aus. | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | Zerlege den URL $url in seine Komponenten und liefere diese zurück. | ||||||||||||||||||||||||||||||||||||||||||
| 504 | Für eine Komponente, die nicht im URL enthalten ist, wird ein | ||||||||||||||||||||||||||||||||||||||||||
| 505 | Leerstring ('') geliefert. | ||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | Ein vollständiger URL hat die Form: | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | schema://[user[:password]@]host[:port]/[path][?query][#fragment] | ||||||||||||||||||||||||||||||||||||||||||
| 510 | ------ ---- -------- ---- ---- ---- ----- -------- | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 1 2 3 4 5 6 7 8 | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | 1 = Schema (http, ftp, ...) | ||||||||||||||||||||||||||||||||||||||||||
| 514 | 2 = Benutzername | ||||||||||||||||||||||||||||||||||||||||||
| 515 | 3 = Passwort | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 4 = Hostname (kann auch IP-Adresse sein) | ||||||||||||||||||||||||||||||||||||||||||
| 517 | 5 = Port | ||||||||||||||||||||||||||||||||||||||||||
| 518 | 6 = Pfad (Gesamtpfad, evtl. einschließlich Pathinfo) | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 7 = Querystring | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 8 = Searchstring (wird nicht an den Server übermittelt) | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | Die Funktion akzeptiert auch unvollständige HTTP URLs: | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | http://host.domain | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | http://host.domain:port/ | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | http://host.domain:port/this/is/a/path | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | /this/is/a/path?arg1=val1&arg2=val2&arg3=val3#text | ||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | is/a/path?arg1=val1&arg2=val2&arg3=val3 | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | path?arg1=val1&arg2=val2&arg3=val3 | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | ?arg1=val1&arg2=val2&arg3=val3 | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | Der Querystring ist alles nach '?' und ggf. bis '#', falls angegeben. | ||||||||||||||||||||||||||||||||||||||||||
| 539 | Der konkrete Aufbau des Querystring, wie Trennzeichen usw., spielt | ||||||||||||||||||||||||||||||||||||||||||
| 540 | keine Rolle. | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | 9 | ▶ | sub split { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split: called CC=12 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 9 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 548 | 9 | my $url = shift; | |||||||||||||||||||||||||||||||||||||||||
| 549 | # @_: @opt | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | # Optionen | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | 9 | my $debug = 0; | |||||||||||||||||||||||||||||||||||||||||
| 554 | 9 | my $defaultSchema = undef; | |||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | 9 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | Quiq::Option->extract(\@_, | |||||||||||||||||||||||||||||||||||||||||
| 558 | -defaultSchema => \$defaultSchema, | ||||||||||||||||||||||||||||||||||||||||||
| 559 | -debug => \$debug, | ||||||||||||||||||||||||||||||||||||||||||
| 560 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | # Code | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 9 | my ($schema,$user,$passw,$host,$port,$path,$query,$frag) = ('') x 8; | |||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 9 | ▶ | if ($defaultSchema && $url !~ m|^(.+)://|) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$defaultSchema and not $url =~ m[^(.+)://]
MC/DC0%0/2
$defaultSchema and not $url =~ m[^(.+)://]
$defaultSchema
not $url =~ m[^(.+)://]
Truth table33%1/3
A and not(B)
A= $defaultSchemaB= not $url =~ m[^(.+)://]
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | # Wir fügen Defaultschema hinzu, wenn keins angegeben ist | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | $url = "$defaultSchema$url"; | |||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||
| 571 | 9 | ▶ | if ($url =~ s|^(.+)://([^/?#]+)||) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | # protocol://user:passw@host:port | ||||||||||||||||||||||||||||||||||||||||||
| 573 | 5 | $schema = $1; | |||||||||||||||||||||||||||||||||||||||||
| 574 | 5 | my ($part1,$part2) = split /@/,$2; | |||||||||||||||||||||||||||||||||||||||||
| 575 | 5 | ▶ | ($user,$passw) = split /:/,$part1 if $part2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 5 | ▶ | $passw = '' if !defined $passw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 577 | 5 | ▶ | ($host,$port) = split /:/,$part2? $part2: $part1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | 5 | ▶ | $port = '' if !defined $port; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||
| 580 | 9 | ▶ | if ($url =~ s|#([^#]*)$||) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | # Searchstring nach # | ||||||||||||||||||||||||||||||||||||||||||
| 582 | 4 | $frag = $1; | |||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 9 | ▶ | if ($url =~ s|\?([^?]*)$||) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | # Querystring nach ? | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 6 | $query = $1; | |||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||
| 589 | 9 | $path = $url; # Rest ist Pfad | |||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | 9 | ▶ | if ($debug) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | print "schema=$schema\n"; | |||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | print "user=$user\n"; | |||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | print "password=$passw=\n"; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | print "host=$host\n"; | |||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | print "port=$port\n"; | |||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | print "path=$path\n"; | |||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | print "query=$query\n"; | |||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | print "frag=$frag\n"; | |||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | 9 | return ($schema,$user,$passw,$host,$port,$path,$query,$frag); | |||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 1.240 | ||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||
| 621 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 622 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||
| 630 | # eof | ||||||||||||||||||||||||||||||||||||||||||