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