blib/lib/OAuth/Lite2/Agent/PSGIMock.pm

filter: Statementstmt 96.4% 27 / 28 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 2 / 2 totaltotal 95.0% 38 / 40 SCAR 0.0
CC
1
Cov
96%
__ANON__
2.0
request
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/OAuth/Lite2/Formatter/Text.pm ↑ Summary blib/lib/OAuth/Lite2.pm »
1 package OAuth::Lite2::Agent::PSGIMock;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use Params::Validate qw(CODEREF);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use HTTP::Message::PSGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Try::Tiny qw/try catch/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 OAuth::Lite2::Agent::PSGIMock - Agent class for test which use PSGI App
14  
15 =head2 SYNOPSIS
16  
17 use Test::More;
18  
19 my $endpoint = OAuth::Lite2::Server::Endpoint::Token->new(
20 data_handler => 'YourApp::DataHandler',
21 );
22  
23 my $agent = OAuth::Lite2::Agent::PSGIMock->new( app => $endpoint );
24  
25 my $client = OAuth::Lite2::Client::UsernameAndPassword->new(
26 client_id => q{foo},
27 client_secret => q{bar},
28 agent => $agent,
29 );
30  
31 my $res = $client->get_access_token(
32 username => q{buz},
33 password => q{huga},
34 scope => q{email},
35 );
36  
37 is($res->access_token, ...);
38 is($res->refresh_token, ...);
39  
40  
41 =head1 DESCRIPTION
42  
43 This class is useful for test to check if your PSGI based
44 server application acts as expected.
45  
46 =head1 METHODS
47  
48 =head2 new (%args)
49  
50 parameters
51  
52 =over 4
53  
54 =item app (PSGI application)
55  
56 =back
57  
58 =cut
59  
60 sub new {
61 6 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
62  
63 6 my %args = Params::Validate::validate(@_, {
64 app => 1,
65 });
66  
67 my $self = bless {
68 app => $args{app},
69 6 }, $class;
70  
71 6 return $self;
72 }
73  
74 =head2 request ($req)
75  
76 handle request with PSIG application you set at constructor
77  
78 =cut
79  
80 sub request {
81 54 ▶ my ($self, $req) = @_;
Subroutine request: called CC=1 SCAR=0.1
Pod documented
82 my $res = try {
83 54 ▶ HTTP::Response->from_psgi($self->{app}->($req->to_psgi));
Subroutine __ANON__: called CC=1 SCAR=0.0
84 } catch {
85 0 ▶ HTTP::Response->from_psgi([500, [ "Content-Type" => "text/plain" ], [ $_ ] ]);
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 54 };
87 54 return $res;
88 }
89  
90 7 1;
91  
92 =head1 SEE ALSO
93  
94 L<OAuth::Lite2::Client::Agent>,
95 L<OAuth::Lite2::Client::Agent::Strict>
96 L<OAuth::Lite2::Client::Agent::Dump>
97  
98 =head1 AUTHOR
99  
100 Lyo Kato, C<lyo.kato _at_ gmail.com>
101  
102 =head1 COPYRIGHT AND LICENSE
103  
104 This library is free software; you can redistribute it and/or modify
105 it under the same terms as Perl itself, either Perl version 5.8.8 or,
106 at your option, any later version of Perl 5 you may have available.
107  
108 =cut
« blib/lib/OAuth/Lite2/Formatter/Text.pm ↑ Summary blib/lib/OAuth/Lite2.pm »