OAuth/Request/Mojo.pm

filter: Statementstmt 38.8% 21 / 54 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 42.8% 6 / 14 Podpod 100% 8 / 8 totaltotal 33.6% 35 / 104 SCAR 42.2
CC
12
Cov
27%
content_is_form
20.0
header
20.0
request_with
12.0
CRAP 68.2
↑ Summary OAuth.pm »
1 package WWW::OAuth::Request::Mojo;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Class::Tiny::Chained 'request';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 with 'WWW::OAuth::Request';
12  
13 1 our $VERSION = '0.006';
14  
15 sub method {
16 0 ▶ my $self = shift;
Subroutine method: not called CC=2 SCAR=17.9
Pod documented
17 0 ▶ return $self->request->method unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
18 0 $self->request->method(shift);
19 0 return $self;
20 }
21  
22 sub url {
23 0 ▶ my $self = shift;
Subroutine url: not called CC=2 SCAR=17.9
Pod documented
24 0 ▶ return $self->request->url->to_string unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
25 0 require Mojo::URL;
26 0 $self->request->url(Mojo::URL->new(shift));
27 0 return $self;
28 }
29  
30 sub content {
31 0 ▶ my $self = shift;
Subroutine content: not called CC=2 SCAR=17.9
Pod documented
32 0 ▶ return $self->request->body unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
33 0 $self->request->body(shift);
34 0 return $self;
35 }
36  
37 sub content_is_form {
38 0 ▶ my $self = shift;
Subroutine content_is_form: not called CC=4 SCAR=30.0
Pod documented
39 0 ▶ return 0 if $self->request->content->is_multipart;
Branch: 1 branch
BranchTrueFalseTotal
if $self->request->content->is_multipart 0 0 0
40 0 my $content_type = $self->request->headers->content_type;
41 0 ▶ return 0 unless defined $content_type and $content_type =~ m!application/x-www-form-urlencoded!i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content_type and $content_type =~ m[application/x-www-form-urlencoded]i 0 0 0
Condition0%0/3
defined $content_type and $content_type =~ m[application/x-www-form-urlencoded]i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $content_type and $content_type =~ m[application/x-www-form-urlencoded]i
defined $content_type $content_type =~ m[application/x-www-form-urlencoded]i
Truth table0%0/3
A and B
A= defined $content_typeB= $content_type =~ m[application/x-www-form-urlencoded]i
ABresult
0X0
100
111
42 0 return 1;
43 }
44  
45 0 ▶sub query_pairs { shift->request->query_params->pairs }
Subroutine query_pairs: not called CC=1 SCAR=6.9
Pod documented
46  
47 0 ▶sub body_pairs { require Mojo::Parameters; Mojo::Parameters->new(shift->request->body)->pairs }
Subroutine body_pairs: not called CC=1 SCAR=6.9
Pod documented
48  
49 sub header {
50 0 ▶ my $self = shift;
Subroutine header: not called CC=4 SCAR=30.0
Pod documented
51 0 my $name = shift;
52 0 ▶ croak 'No header to set/retrieve' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
53 0 ▶ return $self->request->headers->header($name) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
54 0 ▶ my @values = ref $_[0] eq 'ARRAY' ? @{$_[0]} : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 0 0
55 0 $self->request->headers->header($name => @values);
56 0 return $self;
57 }
58  
59 sub request_with {
60 0 ▶ my ($self, $ua, $cb) = @_;
Subroutine request_with: not called CC=3 SCAR=24.8
Pod documented
61 0 ▶ croak 'Unknown user-agent object' unless blessed $ua and $ua->isa('Mojo::UserAgent');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($ua) and $ua->isa("Mojo::UserAgent") 0 0 0
Condition0%0/3
builtin::blessed($ua) and $ua->isa("Mojo::UserAgent")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($ua) and $ua->isa("Mojo::UserAgent")
builtin::blessed($ua) $ua->isa("Mojo::UserAgent")
Truth table0%0/3
A and B
A= builtin::blessed($ua)B= $ua->isa("Mojo::UserAgent")
ABresult
0X0
100
111
62 0 my $tx = $ua->build_tx($self->method, $self->url, $self->request->headers->to_hash, $self->content);
63 0 return $ua->start($tx, $cb);
64 }
65  
66 1 1;
67  
68 =head1 NAME
69  
70 WWW::OAuth::Request::Mojo - HTTP Request container for Mojo::Message::Request
71  
72 =head1 SYNOPSIS
73  
74 my $req = WWW::OAuth::Request::Mojo->new(request => $mojo_request);
75 my $tx = $req->request_with(Mojo::UserAgent->new);
76  
77 =head1 DESCRIPTION
78  
79 L<WWW::OAuth::Request::Mojo> is a request container for L<WWW::OAuth> that
80 wraps a L<Mojo::Message::Request> object, which is used by L<Mojo::UserAgent>.
81 It performs the role L<WWW::OAuth::Request>.
82  
83 =head1 ATTRIBUTES
84  
85 L<WWW::OAuth::Request::Mojo> implements the following attributes.
86  
87 =head2 request
88  
89 my $mojo_request = $req->request;
90 $req = $req->request($mojo_request);
91  
92 L<Mojo::Message::Request> object to authenticate.
93  
94 =head1 METHODS
95  
96 L<WWW::OAuth::Request::Mojo> composes all methods from L<WWW::OAuth::Request>,
97 and implements the following new ones.
98  
99 =head2 body_pairs
100  
101 my $pairs = $req->body_pairs;
102  
103 Return body parameters from L</"request"> as an even-sized arrayref of keys and
104 values.
105  
106 =head2 content
107  
108 my $content = $req->content;
109 $req = $req->content('foo=1&bar=2');
110  
111 Set or return request content from L</"request">.
112  
113 =head2 content_is_form
114  
115 my $bool = $req->content_is_form;
116  
117 Check whether L</"request"> has single-part content and a C<Content-Type>
118 header of C<application/x-www-form-urlencoded>.
119  
120 =head2 header
121  
122 my $header = $req->header('Content-Type');
123 $req = $req->header(Authorization => 'foo bar');
124  
125 Set or return a request header from L</"request">.
126  
127 =head2 method
128  
129 my $method = $req->method;
130 $req = $req->method('GET');
131  
132 Set or return request method from L</"request">.
133  
134 =head2 query_pairs
135  
136 my $pairs = $req->query_pairs;
137  
138 Return query parameters from L</"request"> as an even-sized arrayref of keys
139 and values.
140  
141 =head2 request_with
142  
143 my $tx = $req->request_with(Mojo::UserAgent->new);
144 $req->request_with(Mojo::UserAgent->new, sub {
145 my ($ua, $tx) = @_;
146 ...
147 });
148  
149 Run request with passed L<Mojo::UserAgent> user-agent object, and return
150 L<Mojo::Transaction> object, as in L<Mojo::UserAgent/"start">. A callback can
151 be passed to perform the request non-blocking.
152  
153 =head2 url
154  
155 my $url = $req->url;
156 $req = $req->url('http://example.com/api/');
157  
158 Set or return request URL from L</"request">.
159  
160 =head1 BUGS
161  
162 Report any issues on the public bugtracker.
163  
164 =head1 AUTHOR
165  
166 Dan Book <dbook@cpan.org>
167  
168 =head1 COPYRIGHT AND LICENSE
169  
170 This software is Copyright (c) 2015 by Dan Book.
171  
172 This is free software, licensed under:
173  
174 The Artistic License 2.0 (GPL Compatible)
175  
176 =head1 SEE ALSO
177  
178 L<Mojo::UserAgent>
↑ Summary OAuth.pm »