| 1 | #======================================================================== | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Badger::Codec::URL | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # DESCRIPTION | ||||||||||||||||||||||||||||
| 6 | # Codec module for URL encoding/decoding | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # AUTHOR | ||||||||||||||||||||||||||||
| 9 | # Andy Wardley <abw@wardley.org> | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | #======================================================================== | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | package Badger::Codec::URL; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | use Badger::Class | ||||||||||||||||||||||||||||
| 16 | 1 | version => 0.01, | |||||||||||||||||||||||||||
| 17 | 1 | ▶ | base => 'Badger::Codec::URI'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # cache of escaped characters is shared with Badger::Codec::URI | ||||||||||||||||||||||||||||
| 20 | 1 | our $URI_ESCAPES = $Badger::Codec::URI::URI_ESCAPES; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub encode_url { | ||||||||||||||||||||||||||||
| 23 | 1 | ▶ | my $url = shift; | ||||||||||||||||||||||||||
|
Subroutine
encode_url: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | utf8::encode($url) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$] >= "5.008" and utf8::is_utf8($url)
MC/DC0%0/2
$] >= "5.008" and utf8::is_utf8($url)
$] >= "5.008"
utf8::is_utf8($url)
Truth table33%1/3
A and B
A= $] >= "5.008"B= utf8::is_utf8($url)
| |||||||||||||||||||||||||||||
| 26 | if $] >= 5.008 && utf8::is_utf8($url); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | $URI_ESCAPES ||= { | ||||||||||||||||||||||||||||
| 29 | 1 | ▶ | map { ( chr($_), sprintf("%%%02X", $_) ) } | ||||||||||||||||||||||||||
|
Condition50%1/2
$Badger::Codec::URL::URI_ESCAPES ||= {map({chr $_, sprintf("%%%02X", $_);} 0..255)}
MC/DC0%0/1
$Badger::Codec::URL::URI_ESCAPES ||= {map({chr $_, sprintf("%%%02X", $_);} 0..255)}
$Badger::Codec::URL::URI_ESCAPES
Truth table50%1/2
A
A= $Badger::Codec::URL::URI_ESCAPES
| |||||||||||||||||||||||||||||
| 30 | (0..255) | ||||||||||||||||||||||||||||
| 31 | }; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # the different between the URL and URI encoding is that URL does | ||||||||||||||||||||||||||||
| 34 | # not escape any of: ; / ? : @ & = + $ | ||||||||||||||||||||||||||||
| 35 | 1 | $url =~ s/([^;\/?:@&=+\$,A-Za-z0-9\-_.!~*'()])/$URI_ESCAPES->{$1}/eg; | |||||||||||||||||||||||||||
| 36 | 1 | $url; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | *decode_url = \&Badger::Codec::URI::decode_uri; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | sub encode { | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | shift; | ||||||||||||||||||||||||||
|
Subroutine
encode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 0 | goto &encode_url; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub decode { | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | shift; | ||||||||||||||||||||||||||
|
Subroutine
decode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 0 | goto &decode_url; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub encoder { | ||||||||||||||||||||||||||||
| 52 | 1 | ▶ | \&encode_url; | ||||||||||||||||||||||||||
|
Subroutine
encoder: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub decoder { | ||||||||||||||||||||||||||||
| 56 | 1 | ▶ | \&decode_url; | ||||||||||||||||||||||||||
|
Subroutine
decoder: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | 1; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||||||||||