| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::OAuth::Request::HTTP_Request; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 971 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 56 |  | 
| 4 | 2 |  |  | 2 |  | 8 | use warnings; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 63 |  | 
| 5 | 2 |  |  | 2 |  | 532 | use Class::Tiny::Chained 'request'; | 
|  | 2 |  |  |  |  | 3479 |  | 
|  | 2 |  |  |  |  | 16 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 2 |  |  | 2 |  | 426 | use Carp 'croak'; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 111 |  | 
| 8 | 2 |  |  | 2 |  | 10 | use Scalar::Util 'blessed'; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 108 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 2 |  |  | 2 |  | 485 | use Role::Tiny::With; | 
|  | 2 |  |  |  |  | 220 |  | 
|  | 2 |  |  |  |  | 1030 |  | 
| 11 |  |  |  |  |  |  | with 'WWW::OAuth::Request'; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | our $VERSION = '0.005'; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub method { | 
| 16 | 3 |  |  | 3 | 1 | 7838 | my $self = shift; | 
| 17 | 3 | 100 |  |  |  | 72 | return $self->request->method unless @_; | 
| 18 | 1 |  |  |  |  | 26 | $self->request->method(shift); | 
| 19 | 1 |  |  |  |  | 13 | return $self; | 
| 20 |  |  |  |  |  |  | } | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub url { | 
| 23 | 7 |  |  | 7 | 1 | 1151 | my $self = shift; | 
| 24 | 7 | 100 |  |  |  | 93 | return $self->request->uri->as_string unless @_; | 
| 25 | 3 |  |  |  |  | 70 | $self->request->uri(shift); | 
| 26 | 3 |  |  |  |  | 959 | return $self; | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub content { | 
| 30 | 7 |  |  | 7 | 1 | 708 | my $self = shift; | 
| 31 | 7 | 100 |  |  |  | 95 | return $self->request->content unless @_; | 
| 32 | 3 |  |  |  |  | 64 | $self->request->content(shift); | 
| 33 | 3 |  |  |  |  | 69 | return $self; | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | sub content_is_form { | 
| 37 | 5 |  |  | 5 | 1 | 441 | my $self = shift; | 
| 38 | 5 |  |  |  |  | 94 | my @parts = $self->request->parts; | 
| 39 | 5 | 100 |  |  |  | 111 | return 0 if @parts; | 
| 40 | 4 |  |  |  |  | 83 | my $content_type = $self->request->headers->content_type; | 
| 41 | 4 | 100 | 66 |  |  | 110 | return 0 unless defined $content_type and $content_type =~ m!application/x-www-form-urlencoded!i; | 
| 42 | 2 |  |  |  |  | 11 | return 1; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | sub header { | 
| 46 | 13 |  |  | 13 | 1 | 3552 | my $self = shift; | 
| 47 | 13 |  |  |  |  | 18 | my $name = shift; | 
| 48 | 13 | 50 |  |  |  | 28 | croak 'No header to set/retrieve' unless defined $name; | 
| 49 | 13 | 100 |  |  |  | 159 | return scalar $self->request->header($name) unless @_; | 
| 50 | 6 |  |  |  |  | 137 | $self->request->header($name => shift); | 
| 51 | 6 |  |  |  |  | 256 | return $self; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | sub request_with { | 
| 55 | 0 |  |  | 0 | 1 |  | my ($self, $ua) = @_; | 
| 56 | 0 | 0 |  |  |  |  | croak 'Invalid user-agent object' unless blessed $ua; | 
| 57 | 0 | 0 | 0 |  |  |  | if ($ua->isa('LWP::UserAgent') or $ua->isa('HTTP::Thin')) { | 
|  |  | 0 |  |  |  |  |  | 
| 58 | 0 |  |  |  |  |  | return $ua->request($self->request); | 
| 59 |  |  |  |  |  |  | } elsif ($ua->isa('Net::Async::HTTP')) { | 
| 60 | 0 |  |  |  |  |  | return $ua->do_request(request => $self->request); | 
| 61 |  |  |  |  |  |  | } else { | 
| 62 | 0 |  |  |  |  |  | my $class = blessed $ua; | 
| 63 | 0 |  |  |  |  |  | croak "Unknown user-agent class $class"; | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | 1; | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =head1 NAME | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | WWW::OAuth::Request::HTTP_Request - HTTP Request container for HTTP::Request | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | my $req = WWW::OAuth::Request::HTTP_Request->new(request => $http_request); | 
| 76 |  |  |  |  |  |  | $req->request_with(LWP::UserAgent->new); | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | L is a request container for L | 
| 81 |  |  |  |  |  |  | that wraps a L object, which can be used by several user-agents | 
| 82 |  |  |  |  |  |  | like L, L, and L. It performs the | 
| 83 |  |  |  |  |  |  | role L. | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | L implements the following attributes. | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =head2 request | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | my $http_request = $req->request; | 
| 92 |  |  |  |  |  |  | $req             = $req->request(HTTP::Request->new(GET => $url)); | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | L object to authenticate. | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =head1 METHODS | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | L composes all methods from | 
| 99 |  |  |  |  |  |  | L, and implements the following new ones. | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | =head2 content | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | my $content = $req->content; | 
| 104 |  |  |  |  |  |  | $req        = $req->content('foo=1&bar=2'); | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | Set or return request content from L"request">. | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | =head2 content_is_form | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | my $bool = $req->content_is_form; | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | Check whether L"request"> has single-part content and a C | 
| 113 |  |  |  |  |  |  | header of C. | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =head2 header | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | my $header = $req->header('Content-Type'); | 
| 118 |  |  |  |  |  |  | $req       = $req->header(Authorization => 'Basic foobar'); | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | Set or return a request header from L"request">. | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | =head2 method | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | my $method = $req->method; | 
| 125 |  |  |  |  |  |  | $req       = $req->method('GET'); | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | Set or return request method from L"request">. | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =head2 request_with | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | $http_response = $req->request_with(LWP::UserAgent->new); | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | Run request with passed user-agent object, and return L object. | 
| 134 |  |  |  |  |  |  | User-agent may be L, L, or L. If | 
| 135 |  |  |  |  |  |  | run with L, the return value is a L yielding the | 
| 136 |  |  |  |  |  |  | L object as in L<< "do_request" in Net::Async::HTTP|Net::Async::HTTP/"$response = $http->do_request( %args )->get" >>. | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | =head2 url | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | my $url = $req->url; | 
| 141 |  |  |  |  |  |  | $req    = $req->url('http://example.com/api/'); | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | Set or return request URL from L"request">. | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =head1 BUGS | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | Report any issues on the public bugtracker. | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =head1 AUTHOR | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | Dan Book | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | This software is Copyright (c) 2015 by Dan Book. | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | This is free software, licensed under: | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | The Artistic License 2.0 (GPL Compatible) | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | L, L, L |