line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OAuth::Lite2::Formatters; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
23969
|
use strict; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
220
|
|
4
|
8
|
|
|
8
|
|
37
|
use warnings; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
178
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
2961
|
use OAuth::Lite2::Formatter::JSON; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
199
|
|
7
|
8
|
|
|
8
|
|
2871
|
use OAuth::Lite2::Formatter::XML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use OAuth::Lite2::Formatter::FormURLEncoded; |
9
|
|
|
|
|
|
|
use OAuth::Lite2::Formatter::Text; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %FORMATTERS_BY_TYPE; |
12
|
|
|
|
|
|
|
my %FORMATTERS_BY_NAME; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub add_formatter { |
15
|
|
|
|
|
|
|
my ($class, $formatter) = @_; |
16
|
|
|
|
|
|
|
$FORMATTERS_BY_NAME{$formatter->name} = $formatter; |
17
|
|
|
|
|
|
|
$FORMATTERS_BY_TYPE{$formatter->type} = $formatter; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
__PACKAGE__->add_formatter( OAuth::Lite2::Formatter::JSON->new ); |
21
|
|
|
|
|
|
|
__PACKAGE__->add_formatter( OAuth::Lite2::Formatter::XML->new ); |
22
|
|
|
|
|
|
|
__PACKAGE__->add_formatter( OAuth::Lite2::Formatter::FormURLEncoded->new ); |
23
|
|
|
|
|
|
|
__PACKAGE__->add_formatter( OAuth::Lite2::Formatter::Text->new ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get_formatter_by_name { |
26
|
|
|
|
|
|
|
my ($class, $name) = @_; |
27
|
|
|
|
|
|
|
return unless $name; |
28
|
|
|
|
|
|
|
return $FORMATTERS_BY_NAME{$name}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub get_formatter_by_type { |
32
|
|
|
|
|
|
|
my ($class, $type) = @_; |
33
|
|
|
|
|
|
|
return unless $type; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# If content-type includes subtype, top-level media type is only used. |
36
|
|
|
|
|
|
|
if ($type =~ /;/){ |
37
|
|
|
|
|
|
|
$type = $`; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return $FORMATTERS_BY_TYPE{$type}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
OAuth::Lite2::Formatters - OAuth 2.0 formatters store |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $formatter = OAuth::Lite2::Formatter->get_formatter_by_name("json"); |
50
|
|
|
|
|
|
|
my $formatter = OAuth::Lite2::Formatter->get_formatter_by_type("application/json"); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $obj = $formatter->parse( $string ); |
53
|
|
|
|
|
|
|
$string = $formatter->format( $obj ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
OAuth 2.0 formatters store. |
58
|
|
|
|
|
|
|
from draft-v8, specification requires only JSON format. |
59
|
|
|
|
|
|
|
This library leaves the other formatters for interop. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 METHODS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 get_formatter_by_name( $name ) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return formatter by name |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 get_formatter_by_type( $content_type ) |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return formatter by content type |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SEE ALSO |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
L |
74
|
|
|
|
|
|
|
L |
75
|
|
|
|
|
|
|
L |
76
|
|
|
|
|
|
|
L |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AUTHOR |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Lyo Kato, Elyo.kato@gmail.comE |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Copyright (C) 2010 by Lyo Kato |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
87
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
88
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |