| 1 | package OAuth::Lite2::Formatters; | ||||||||||
| 2 | |||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 8 | ▶ | use OAuth::Lite2::Formatter::JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 8 | ▶ | use OAuth::Lite2::Formatter::XML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 8 | ▶ | use OAuth::Lite2::Formatter::FormURLEncoded; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 8 | ▶ | use OAuth::Lite2::Formatter::Text; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 8 | my %FORMATTERS_BY_TYPE; | |||||||||
| 12 | my %FORMATTERS_BY_NAME; | ||||||||||
| 13 | |||||||||||
| 14 | 32 | ▶ | sub add_formatter { | ||||||||
|
Subroutine
add_formatter: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 15 | 32 | my ($class, $formatter) = @_; | |||||||||
| 16 | 32 | $FORMATTERS_BY_NAME{$formatter->name} = $formatter; | |||||||||
| 17 | 32 | $FORMATTERS_BY_TYPE{$formatter->type} = $formatter; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 8 | __PACKAGE__->add_formatter( OAuth::Lite2::Formatter::JSON->new ); | |||||||||
| 21 | 8 | __PACKAGE__->add_formatter( OAuth::Lite2::Formatter::XML->new ); | |||||||||
| 22 | 8 | __PACKAGE__->add_formatter( OAuth::Lite2::Formatter::FormURLEncoded->new ); | |||||||||
| 23 | 8 | __PACKAGE__->add_formatter( OAuth::Lite2::Formatter::Text->new ); | |||||||||
| 24 | |||||||||||
| 25 | 58 | ▶ | sub get_formatter_by_name { | ||||||||
|
Subroutine
get_formatter_by_name: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 26 | 58 | my ($class, $name) = @_; | |||||||||
| 27 | 58 | ▶ | return unless $name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 58 | return $FORMATTERS_BY_NAME{$name}; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 59 | ▶ | sub get_formatter_by_type { | ||||||||
|
Subroutine
get_formatter_by_type: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 32 | 59 | my ($class, $type) = @_; | |||||||||
| 33 | 59 | ▶ | return unless $type; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | |||||||||||
| 35 | # If content-type includes subtype, top-level media type is only used. | ||||||||||
| 36 | 59 | ▶ | if ($type =~ /;/){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 1 | $type = $`; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 59 | 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<OAuth::Lite2::Formatter> | ||||||||||
| 74 | L<OAuth::Lite2::Formatter::JSON> | ||||||||||
| 75 | L<OAuth::Lite2::Formatter::XML> | ||||||||||
| 76 | L<OAuth::Lite2::Formatter::FormURLEncoded> | ||||||||||
| 77 | |||||||||||
| 78 | =head1 AUTHOR | ||||||||||
| 79 | |||||||||||
| 80 | Lyo Kato, E<lt>lyo.kato@gmail.comE<gt> | ||||||||||
| 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 | 8 | 1; | |||||||||