line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OAuth::Lite2::Util; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
2949
|
use strict; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
249
|
|
4
|
8
|
|
|
8
|
|
42
|
use warnings; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
264
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
45
|
use base 'Exporter'; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
845
|
|
7
|
8
|
|
|
8
|
|
1835
|
use URI::Escape; |
|
8
|
|
|
|
|
6669
|
|
|
8
|
|
|
|
|
674
|
|
8
|
8
|
|
|
8
|
|
54
|
use Scalar::Util qw(blessed); |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
575
|
|
9
|
8
|
|
|
8
|
|
4916
|
use Hash::MultiValue; |
|
8
|
|
|
|
|
7439
|
|
|
8
|
|
|
|
|
3546
|
|
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
|
231
|
|
|
231
|
1
|
390
|
my $param = shift; |
42
|
231
|
|
|
|
|
329
|
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
|
736
|
my $param = shift; |
51
|
13
|
|
|
|
|
23
|
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
|
438
|
my $content = shift; |
60
|
1
|
|
|
|
|
9
|
my $params = Hash::MultiValue->new; |
61
|
1
|
|
|
|
|
51
|
for my $pair (split /\&/, $content) { |
62
|
4
|
|
|
|
|
68
|
my ($key, $value) = split /\=/, $pair; |
63
|
4
|
|
50
|
|
|
14
|
$key = decode_param($key ||''); |
64
|
4
|
|
50
|
|
|
28
|
$value = decode_param($value||''); |
65
|
4
|
|
|
|
|
23
|
$params->add($key, $value); |
66
|
|
|
|
|
|
|
} |
67
|
1
|
|
|
|
|
16
|
return $params; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 build_content ($params) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub build_content { |
75
|
34
|
|
|
34
|
1
|
8039
|
my $params = shift; |
76
|
34
|
100
|
66
|
|
|
177
|
$params = $params->as_hashref_mixed |
77
|
|
|
|
|
|
|
if blessed($params) && $params->isa('Hash::MultiValue'); |
78
|
34
|
|
|
|
|
71
|
my @pairs; |
79
|
34
|
|
|
|
|
88
|
for my $key (keys %$params) { |
80
|
110
|
|
|
|
|
1739
|
my $k = encode_param($key); |
81
|
110
|
|
|
|
|
3014
|
my $v = $params->{$key}; |
82
|
110
|
100
|
|
|
|
173
|
if (ref($v) eq 'ARRAY') { |
83
|
2
|
|
|
|
|
6
|
for my $av (@$v) { |
84
|
4
|
|
|
|
|
71
|
push(@pairs, sprintf(q{%s=%s}, $k, encode_param($av))); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} else { |
87
|
108
|
|
|
|
|
137
|
push(@pairs, sprintf(q{%s=%s}, $k, encode_param($v))); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
34
|
|
|
|
|
916
|
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 |