line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OAuth::Lite2::Util; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
24198
|
use strict; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
353
|
|
4
|
11
|
|
|
11
|
|
61
|
use warnings; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
306
|
|
5
|
|
|
|
|
|
|
|
6
|
11
|
|
|
11
|
|
62
|
use base 'Exporter'; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
1003
|
|
7
|
11
|
|
|
11
|
|
1900
|
use URI::Escape; |
|
11
|
|
|
|
|
3216
|
|
|
11
|
|
|
|
|
741
|
|
8
|
11
|
|
|
11
|
|
66
|
use Scalar::Util qw(blessed); |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
665
|
|
9
|
11
|
|
|
11
|
|
1986
|
use Hash::MultiValue; |
|
11
|
|
|
|
|
5476
|
|
|
11
|
|
|
|
|
5491
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => [qw( |
12
|
|
|
|
|
|
|
encode_param |
13
|
|
|
|
|
|
|
decode_param |
14
|
|
|
|
|
|
|
parse_content |
15
|
|
|
|
|
|
|
build_content |
16
|
|
|
|
|
|
|
)] ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
OAuth::Lite2::Util - utility methods for OAuth 2.0 |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use OAuth::Lite2::Util qw(encode_param, decode_param); |
27
|
|
|
|
|
|
|
my $encoded = encode_param($str); |
28
|
|
|
|
|
|
|
my $origin = decode_param($encoded); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This module exports utility methods for OAuth 2.0. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 encode_param ($str) |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub encode_param { |
41
|
379
|
|
|
379
|
1
|
739
|
my $param = shift; |
42
|
379
|
|
|
|
|
861
|
return URI::Escape::uri_escape($param, '^\w.~-'); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 decode_param ($str) |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub decode_param { |
50
|
13
|
|
|
13
|
1
|
1312
|
my $param = shift; |
51
|
13
|
|
|
|
|
32
|
return URI::Escape::uri_unescape($param); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 parse_content ($content) |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub parse_content { |
59
|
1
|
|
|
1
|
1
|
961
|
my $content = shift; |
60
|
1
|
|
|
|
|
12
|
my $params = Hash::MultiValue->new; |
61
|
1
|
|
|
|
|
148
|
for my $pair (split /\&/, $content) { |
62
|
4
|
|
|
|
|
77
|
my ($key, $value) = split /\=/, $pair; |
63
|
4
|
|
50
|
|
|
12
|
$key = decode_param($key ||''); |
64
|
4
|
|
50
|
|
|
29
|
$value = decode_param($value||''); |
65
|
4
|
|
|
|
|
27
|
$params->add($key, $value); |
66
|
|
|
|
|
|
|
} |
67
|
1
|
|
|
|
|
21
|
return $params; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 build_content ($params) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub build_content { |
75
|
56
|
|
|
56
|
1
|
28399
|
my $params = shift; |
76
|
56
|
100
|
66
|
|
|
272
|
$params = $params->as_hashref_mixed |
77
|
|
|
|
|
|
|
if blessed($params) && $params->isa('Hash::MultiValue'); |
78
|
56
|
|
|
|
|
107
|
my @pairs; |
79
|
56
|
|
|
|
|
463
|
for my $key (keys %$params) { |
80
|
184
|
|
|
|
|
4381
|
my $k = encode_param($key); |
81
|
184
|
|
|
|
|
7240
|
my $v = $params->{$key}; |
82
|
184
|
100
|
|
|
|
383
|
if (ref($v) eq 'ARRAY') { |
83
|
2
|
|
|
|
|
4
|
for my $av (@$v) { |
84
|
4
|
|
|
|
|
59
|
push(@pairs, sprintf(q{%s=%s}, $k, encode_param($av))); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} else { |
87
|
182
|
|
|
|
|
358
|
push(@pairs, sprintf(q{%s=%s}, $k, encode_param($v))); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
56
|
|
|
|
|
2225
|
return join("&", sort @pairs); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHOR |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Lyo Kato, Elyo.kato@gmail.comE |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Copyright (C) 2010 by Lyo Kato |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
104
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
105
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |