line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#======================================================================== |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Badger::Codec::URL |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION |
6
|
|
|
|
|
|
|
# Codec module for URL encoding/decoding |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# AUTHOR |
9
|
|
|
|
|
|
|
# Andy Wardley |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
#======================================================================== |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Badger::Codec::URL; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Badger::Class |
16
|
1
|
|
|
|
|
8
|
version => 0.01, |
17
|
1
|
|
|
1
|
|
7
|
base => 'Badger::Codec::URI'; |
|
1
|
|
|
|
|
2
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# cache of escaped characters is shared with Badger::Codec::URI |
20
|
|
|
|
|
|
|
our $URI_ESCAPES = $Badger::Codec::URI::URI_ESCAPES; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub encode_url { |
23
|
1
|
|
|
1
|
1
|
9
|
my $url = shift; |
24
|
|
|
|
|
|
|
|
25
|
1
|
50
|
33
|
|
|
33
|
utf8::encode($url) |
26
|
|
|
|
|
|
|
if $] >= 5.008 && utf8::is_utf8($url); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$URI_ESCAPES ||= { |
29
|
1
|
|
50
|
|
|
8
|
map { ( chr($_), sprintf("%%%02X", $_) ) } |
|
256
|
|
|
|
|
609
|
|
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
|
|
|
|
|
26
|
$url =~ s/([^;\/?:@&=+\$,A-Za-z0-9\-_.!~*'()])/$URI_ESCAPES->{$1}/eg; |
|
3
|
|
|
|
|
13
|
|
36
|
1
|
|
|
|
|
4
|
$url; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
*decode_url = \&Badger::Codec::URI::decode_uri; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub encode { |
42
|
0
|
|
|
0
|
1
|
0
|
shift; |
43
|
0
|
|
|
|
|
0
|
goto &encode_url; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub decode { |
47
|
0
|
|
|
0
|
1
|
0
|
shift; |
48
|
0
|
|
|
|
|
0
|
goto &decode_url; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub encoder { |
52
|
1
|
|
|
1
|
1
|
3
|
\&encode_url; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub decoder { |
56
|
1
|
|
|
1
|
1
|
2
|
\&decode_url; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |