line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#======================================================================== |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Badger::Codec::URI |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION |
6
|
|
|
|
|
|
|
# Codec module for URI encoding/decoding |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# AUTHOR |
9
|
|
|
|
|
|
|
# Andy Wardley |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
#======================================================================== |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Badger::Codec::URI; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Badger::Class |
16
|
3
|
|
|
|
|
24
|
version => 0.01, |
17
|
3
|
|
|
3
|
|
27
|
base => 'Badger::Codec'; |
|
3
|
|
|
|
|
6
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# cache of escaped characters |
20
|
|
|
|
|
|
|
our $URI_ESCAPES; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub encode_uri { |
23
|
7
|
|
|
7
|
1
|
18
|
my $uri = shift; |
24
|
|
|
|
|
|
|
|
25
|
7
|
50
|
33
|
|
|
32
|
utf8::encode($uri) |
26
|
|
|
|
|
|
|
if $] >= 5.008 && utf8::is_utf8($uri); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$URI_ESCAPES ||= { |
29
|
7
|
|
100
|
|
|
21
|
map { ( chr($_), sprintf("%%%02X", $_) ) } |
|
512
|
|
|
|
|
1202
|
|
30
|
|
|
|
|
|
|
(0..255) |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
7
|
|
|
|
|
62
|
$uri =~ s/([^A-Za-z0-9\-_.!~*'()])/$URI_ESCAPES->{$1}/eg; |
|
4
|
|
|
|
|
13
|
|
34
|
7
|
|
|
|
|
25
|
$uri; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub decode_uri { |
38
|
10
|
|
|
10
|
1
|
23
|
my $uri = shift; |
39
|
10
|
|
|
|
|
20
|
$uri =~ tr/+/ /; |
40
|
10
|
|
|
|
|
26
|
$uri =~ s/%([0-9a-fA-F]{2})/pack("c", hex($1))/ge; |
|
7
|
|
|
|
|
37
|
|
41
|
10
|
|
|
|
|
42
|
$uri; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub encode { |
45
|
0
|
|
|
0
|
1
|
0
|
shift; |
46
|
0
|
|
|
|
|
0
|
goto &encode_uri; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub decode { |
50
|
0
|
|
|
0
|
1
|
0
|
shift; |
51
|
0
|
|
|
|
|
0
|
goto &decode_uri; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub encoder { |
55
|
2
|
|
|
2
|
1
|
5
|
\&encode_uri; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub decoder { |
59
|
2
|
|
|
2
|
1
|
3
|
\&decode_uri; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |