blib/lib/OAuth/Lite2/ParamMethods.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 98.1% 52 / 53 SCAR 11.0
CC
3
Cov
98%
get_param_parser
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« blib/lib/OAuth/Lite2/Formatters.pm ↑ Summary blib/lib/OAuth/Lite2/Agent.pm »
1 package OAuth::Lite2::ParamMethods;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use OAuth::Lite2::ParamMethod::AuthHeader;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use OAuth::Lite2::ParamMethod::FormEncodedBody;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use OAuth::Lite2::ParamMethod::URIQueryParameter;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our %EXPORT_TAGS = ( all => [qw/
13 AUTH_HEADER FORM_BODY URI_QUERY
14 /] );
15  
16 3 our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
17  
18 3 ▶use constant AUTH_HEADER => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use constant FORM_BODY => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use constant URI_QUERY => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 my @METHODS = (
23 OAuth::Lite2::ParamMethod::AuthHeader->new,
24 OAuth::Lite2::ParamMethod::FormEncodedBody->new,
25 OAuth::Lite2::ParamMethod::URIQueryParameter->new,
26 );
27  
28 sub get_param_parser {
29 46 ▶ my ($self, $req) = @_;
Subroutine get_param_parser: called CC=3 SCAR=11.1
Pod documented
30 46 for my $method ( @METHODS ) {
31 83 ▶ return $method if $method->match($req)
Branch: 1 branch
BranchTrueFalseTotal
if $method->match($req) 46 37 83
32 }
33 0 return;
34 }
35  
36 sub get_request_builder {
37 4 ▶ my ($self, $type) = @_;
Subroutine get_request_builder: called CC=1 SCAR=0.0
Pod documented
38 4 return $METHODS[ $type ];
39 }
40  
41 =head1 NAME
42  
43 OAuth::Lite2::ParamMethods - store of builders/parsers for OAuth 2.0 parameters
44  
45 =head1 SYNOPSIS
46  
47 use OAuth::Lite2::ParamMethods qw(AUTH_HEADER FORM_BODY URI_QUERY);
48  
49 # client side
50 my $builder = OAuth::Lite2::ParamMethods->get_request_builder( AUTH_HEADER );
51 my $req = $builder->build_request(...);
52  
53 # server side
54 my $parser = OAuth::Lite2::ParamMethods->get_param_parser( $plack_request )
55 or $app->error("This is not OAuth 2.0 request");
56 my ($token, $params) = $parser->parse( $plack_request );
57  
58 =head1 DESCRIPTION
59  
60 Store of builders/parsers for OAuth 2.0 parameters
61  
62 =head1 CONSTANTS
63  
64 =over 4
65  
66 =item AUTH_HEADER
67  
68 =item FORM_BODY
69  
70 =item URI_QUERY
71  
72 =back
73  
74 =head1 METHODS
75  
76 =head2 get_param_parser( $plack_request )
77  
78 Pass a L<Plack::Request> object and proper parser for the request.
79  
80 my $parser = OAuth::Lite2::ParamMethods->get_param_parser( $plack_request )
81 or $app->error("This is not OAuth 2.0 request");
82 my ($token, $params) = $parser->parse( $plack_request );
83  
84 =head2 get_request_builder( $type )
85  
86 Returns proper HTTP request builder for the passed $type.
87  
88 my $builder = OAuth::Lite2::ParamMethods->get_request_builder( AUTH_HEADER );
89 my $req = $builder->build_request(...);
90  
91 =head1 SEE ALSO
92  
93 L<OAuth::Lite2::ParamMethod::AuthHeader>
94 L<OAuth::Lite2::ParamMethod::FormEncodedBody>
95 L<OAuth::Lite2::ParamMethod::URIQueryParameter>
96  
97 =head1 AUTHOR
98  
99 Lyo Kato, E<lt>lyo.kato@gmail.comE<gt>
100  
101 =head1 COPYRIGHT AND LICENSE
102  
103 Copyright (C) 2010 by Lyo Kato
104  
105 This library is free software; you can redistribute it and/or modify
106 it under the same terms as Perl itself, either Perl version 5.8.8 or,
107 at your option, any later version of Perl 5 you may have available.
108  
109 =cut
110  
111 3 1;
« blib/lib/OAuth/Lite2/Formatters.pm ↑ Summary blib/lib/OAuth/Lite2/Agent.pm »